Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use @edge-runtime/jest-environment #832

Open
zmeecer opened this issue Mar 7, 2024 · 0 comments
Open

Cannot use @edge-runtime/jest-environment #832

zmeecer opened this issue Mar 7, 2024 · 0 comments

Comments

@zmeecer
Copy link

zmeecer commented Mar 7, 2024

Bug Report

Current behavior

During testing my middleware (Edge runtime) I faced with the issue - runtime isn't changing.
Code and configuration below, can assume that's misconfiguration.
The simple test below has passed, although it shouldn't

Expected behavior/code

Switching environment to runtime edge

Additional context/screenshots

test.js

/**
 * @jest-environment @edge-runtime/jest-environment
 */
test('should return the correct value', () => {
  let val = eval('2 + 2');
  expect(val).toBe(4);
});

jest.config.js

const nextJest = require('next/jest');

const createJestConfig = nextJest({
  // Provide the path to your Next.js app to load next.config.js and .env files in your test environment
  dir: './',
});

// Add any custom config to be passed to Jest
const customJestConfig = {
  setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
  testEnvironment: 'jsdom',
};

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig);

jest.setup.js

import '@testing-library/jest-dom';

devDeps from package.json:

  "devDependencies": {
    "@edge-runtime/jest-environment": "^2.3.10",
    "@testing-library/jest-dom": "^6.4.2",
    "@testing-library/react": "^14.2.1",
    "@types/node": "20.11.20",
    "eslint": "^8",
    "eslint-config-next": "14.0.4",
    "eslint-config-prettier": "^9.1.0",
    "jest": "^29.7.0",
    "jest-environment-jsdom": "^29.7.0",
    "typescript": "5.3.3"
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant