jest-date icon indicating copy to clipboard operation
jest-date copied to clipboard

Expect is not defined

Open chrisdobler opened this issue 2 years ago • 1 comments

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?

chrisdobler avatar Mar 10 '23 00:03 chrisdobler

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:

magnusottosson avatar Dec 22 '23 13:12 magnusottosson