jest-date
jest-date copied to clipboard
Expect is not defined
Hello, thanks for writing this extension. I am having an issue getting it set up. When I add the import statement into the setup file as you describe I get this:
ReferenceError: expect is not defined
1 | import 'jest-date';
2 |
Do you have any ideas what could cause this?
In your jest config change setupFiles: ['<rootDir>/test/jest-setup.ts'] to setupFilesAfterEnv: ['<rootDir>/test/jest-setup.ts'] and it should work.
setupFiles are executed before the jest environment is setup and setupFilesAfterEnv after.
From the docs:
In other words, setupFilesAfterEnv modules are meant for code which is repeating in each test file. Having the test framework installed makes Jest globals, jest object and expect accessible in the modules. For example, you can add extra matchers from jest-extended library or call setup and teardown hooks: