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
However whenever I use the render exported from the test-utils files (let's say it's called testUtilRender), my test always return with this error on top of the test result (the test itself correctly):
// ----- yarn test result
ReferenceError: You are trying to `import` a file after the Jest environment has been torn down.
at Object.get Platform [as Platform] (node_modules/react-native/index.js:351:12)
at node_modules/native-base/lib/commonjs/core/hybrid-overlay/HybridProvider.tsx:55:3
at Object.invokeGuardedCallbackProd (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:11308:10)
at invokeGuardedCallback (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:11499:31)
at flushPassiveEffectsImpl (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:14560:11)
PASS src/screens/auth/LoginScreen/index.test.js (17.912 s)
PASS __tests__/App-test.js (18.822 s)
The only way to get trid of the ReferenceError is to explicitly wrap the component I'm testing in <NativeBaseProvider /> in each test file. Setting the wrapper option itself on the test file still result in that error.
// ------ 3. loginScreen.test.js
it('should show email and password input and login button', async () => {
const screen = render(<LoginScreen />, {wrapper: <NativeBaseProvider />}); // this will still cause the ReferenceError
const screen1 = testUtilRender(<LoginScreen />); // this will still cause the ReferenceError
const screen2 = render(<NativeBaseProvider><LoginScreen /></NativeBaseProvider>); // this is fine.
});
Is there something I'm missing? This is my first time testing RN, so I don't know if this is expected behavior or a bug.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
HI, I'm wondering if anyone can help me with this.
I'm using NativeBase, and following the guide here: https://testing-library.com/docs/react-native-testing-library/setup, I have a separate file defining the provider wrapper (the
AllTheProviders
component).However whenever I use the render exported from the
test-utils
files (let's say it's calledtestUtilRender
), my test always return with this error on top of the test result (the test itself correctly):The only way to get trid of the
ReferenceError
is to explicitly wrap the component I'm testing in<NativeBaseProvider />
in each test file. Setting thewrapper
option itself on the test file still result in that error.Is there something I'm missing? This is my first time testing RN, so I don't know if this is expected behavior or a bug.
My package version:
"react": "17.0.2",
"react-native": "0.65.1",
"jest": "^26.6.3",
"@testing-library/react-native": "^7.2.0",
Beta Was this translation helpful? Give feedback.
All reactions