question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

🐛 Bug Report

I have a component that makes use of Animated component from react native. I started writing a test case to simulate onPress of a component, which calls a function that has Animated.timing in it, and setState.

jest works fine, but the tests never stops running, and one unrelated test case that I’ve written before never seem to pass now (which passed before).

running jest --watch, I get this error:

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

      at Function.bezier (node_modules/react-native/Libraries/Animated/src/Easing.js:113:21)
      at ease (node_modules/react-native/Libraries/Animated/src/Easing.js:34:24)
      at TimingAnimation._easing (node_modules/react-native/Libraries/Animated/src/Easing.js:133:18)
      at TimingAnimation.onUpdate (node_modules/react-native/Libraries/Animated/src/animations/TimingAnimation.js:107:45)

 RUNS  src/__tests__/SlideDownMenu.test.js

/home/nrion/Desktop/mobile-ui/PriceInsight_app/node_modules/react-native/Libraries/Animated/src/Easing.js:114
      return _bezier(x1, y1, x2, y2);
             ^
TypeError: _bezier is not a function
    at Function.bezier (/home/nrion/Desktop/mobile-ui/PriceInsight_app/node_modules/react-native/Libraries/Animated/src/Easing.js:224:12)
    at ease (/home/nrion/Desktop/mobile-ui/PriceInsight_app/node_modules/react-native/Libraries/Animated/src/Easing.js:94:21)
    at TimingAnimation._easing (/home/nrion/Desktop/mobile-ui/PriceInsight_app/node_modules/react-native/Libraries/Animated/src/Easing.js:255:16)
    at TimingAnimation.onUpdate (/home/nrion/Desktop/mobile-ui/PriceInsight_app/node_modules/react-native/Libraries/Animated/src/animations/TimingAnimation.js:138:14)
    at ontimeout (timers.js:386:11)
    at tryOnTimeout (timers.js:250:5)
    at Timer.listOnTimeout (timers.js:214:5)

Expected behavior

Tests passes

Link to repl or repo (highly encouraged)

repl.it demo: https://repl.it/repls/PartialGrimyMetadata

Run npx envinfo --preset jest

Environment:
  OS: Linux 4.14
  Node: 6.14.2
  Yarn: 1.7.0
  npm: 3.10.10
  Watchman: Not Found
  Xcode: N/A
  Android Studio: Not Found

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:21
  • Comments:17

github_iconTop GitHub Comments

225reactions
tarunjunejacommented, Aug 28, 2019

I am on react-native 0.60 was struggling with same error

I solved it by adding 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.

34reactions
f4z3k4scommented, Jun 18, 2020

I am using react-native-testing-library and what resolved this error for me was to simply make the callback of the test case async like

it('your test case', () => {...})

becomes:

it('your test case', async () => {...})
Read more comments on GitHub >

github_iconTop Results From Across the Web

You are trying to `import` a file after the Jest environment has ...
Torn down means: Jest already finished running and some part of your code is trying to execute after jest has already finished running...
Read more >
Throwing 'You are importing a file after the Jest environment ...
js:11:22) ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. at BufferList.Readable (node_modules/ ...
Read more >
You are trying to `import` a file after the Jest environment has ...
Javascript – ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. enzymejavascriptjestjsreact-nativereactjs.
Read more >
You are trying to `import` a file after the Jest environment has ...
ReferenceError : You are trying to 'import' a file after the Jest environment has been torn down. Torn down means: Jest already finished...
Read more >
moleculerjs/moleculer - Gitter
ReferenceError : You are trying to import a file after the Jest environment has been torn down. at ../node_modules/consolidate/lib/consolidate.js:867:64 at .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found