You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ReferenceError: You are trying to access a property or method of the Jest environment after it has been torn down.
This appears to be due to the useEffect() cleanup being called after Jest has done its own cleanup; manually unmount()ing the component before exiting the test resolves the issue.
This is problematic since jest --runInBand exits non-zero, causing pipeline failures (even though all tests pass).
Expected behavior
Automatic cleanup has access to the Jest environment, so I do not need to manually unmount().
Steps to Reproduce
// Add to `MyComponent`useEffect(()=>{consthandle=InteractionManager.runAfterInteractions(async()=>{letnextFrame=newPromise((resolve)=>requestAnimationFrame(()=>resolve()));awaitnextFrame();});return()=>{handle.cancel();};},[]);
test('Render example',async()=>{const{toJSON, unmount}=render(<MyComponent/>);expect(toJSON()).toMatchSnapshot();// Uncomment to resolve access Jest environment after teardown.//unmount();});
What you are doing in the workaround is that you are calling unmount() directly in the test, so before afterEach. That causes the useEffect cleanup be called inside the test, and not in "after test" phase.
I'm not sure if cleanup could technically be called by RNLT "inside" the test, as that is controlled by Jest (and you as the user). So the manual unmount() workaround seems the best we can do now. Let me know if you see other options.
Describe the bug
While running tests, I get:
This appears to be due to the
useEffect()
cleanup being called after Jest has done its own cleanup; manuallyunmount()
ing the component before exiting the test resolves the issue.This is problematic since
jest --runInBand
exits non-zero, causing pipeline failures (even though all tests pass).Expected behavior
Automatic cleanup has access to the Jest environment, so I do not need to manually
unmount()
.Steps to Reproduce
Screenshots
Versions
The text was updated successfully, but these errors were encountered: