ReferenceError: You are trying to `import` a file after the Jest environment has been torn down

OK, found a solution.

Should use jest.useFakeTimers()

Note: Put the code above just after import section in your test file.


jest.useFakeTimers()

With above it's extremely important to understand this

jest.useFakeTimers() mocks out setTimeout and other timer functions with mock functions.

If running multiple tests inside of one file or describe block, jest.useFakeTimers(); can be called before each test manually or with a setup function such as beforeEach.

Not doing so will result in the internal usage counter not being reset.