{"id":660,"hash":"8658871d6672358565253df1ace853675e02b2e54b4ed623951fff8655a27e8f","pattern":"ReferenceError: You are trying to `import` a file after the Jest environment has been torn down","full_message":"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.\n\nrunning 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). \n\nrunning jest --watch, I get this error: \n\nReferenceError: You are trying to `import` a file after the Jest environment has been torn down.\n\n      at Function.bezier (node_modules/react-native/Libraries/Animated/src/Easing.js:113:21)\n      at ease (node_modules/react-native/Libraries/Animated/src/Easing.js:34:24)\n      at TimingAnimation._easing (node_modules/react-native/Libraries/Animated/src/Easing.js:133:18)\n      at TimingAnimation.onUpdate (node_modules/react-native/Libraries/Animated/src/animations/TimingAnimation.js:107:45)\n\n RUNS  src/__tests__/SlideDownMenu.test.js\n\n/home/nrion/Desktop/mobile-ui/PriceInsight_app/node_modules/react-native/Libraries/Animated/src/Easing.js:114\n      return _bezier(x1, y1, x2, y2);\n             ^\nTypeError: _bezier is not a function\n    at Function.bezier (/home/nrion/Desktop/mobile-ui/PriceInsight_app/node_modules/react-native/Libraries/Animated/src/Easing.js:224:12)\n    at ease (/home/nrion/Desktop/mobile-ui/PriceInsight_app/node_modules/react-native/Libraries/Animated/src/Easing.js:94:21)\n    at TimingAnimation._easing (/home/nrion/Desktop/mobile-ui/PriceInsight_app/node_modules/react-native/Libraries/Animated/src/Easing.js:255:16)\n    at TimingAnimation.onUpdate (/home/nrion/Desktop/mobile-ui/PriceInsight_app/node_modules/react-native/Libraries/Animated/src/animations/TimingAnimation.js:138:14)\n    at ontimeout (timers.js:386:11)\n    at tryOnTimeout (timers.js:250:5)\n    at Timer.listOnTimeout (timers.js:214:5)\n\nLink to repl\n\nhttps://repl.it/repls/PartialGrimyMetadata\n\nEnvironment:\n\nOS: Linux 4.14\nNode: 6.14.2\nYarn: 1.7.0\nnpm: 3.10.10\nWatchman: Not Found\nXcode: N/A\nAndroid Studio: Not Found","ecosystem":"npm","package_name":"reactjs","package_version":null,"solution":"OK, found a solution.\n\nShould use jest.useFakeTimers().\n\nNote: Put the code above just after import section in your test file.\n\n=== Edited ===\n\nYou can read more about how useFakeTimers work here: https://jestjs.io/docs/timer-mocks\n\nSimply, it mocks functions like setTimeout, setInterval, etc.\n\nIf you do not use jest.useFakeTimers(), you may have async tests that take long to complete, and warnings like the following might be thrown.\n\nYou are trying to access a property or method of the Jest environment after it has been torn down.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/50793885/referenceerror-you-are-trying-to-import-a-file-after-the-jest-environment-has","votes":144,"created_at":"2026-04-19T04:51:27.265542+00:00","updated_at":"2026-04-19T04:51:27.265542+00:00"}