-
-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When testing a Navigation container with jest the test passes, but the process fails #9568
Comments
Hey! Thanks for opening the issue. The issue doesn't seem to contain a link to a repro (a snack.expo.io link or link to a GitHub repo under your username). Can you provide a minimal repro which demonstrates the issue? A repro will help us debug the issue faster. Please try to keep the repro as small as possible and make sure that we can run it without additional setup. |
|
You'd need to use |
Thank you for the response. I tried that in the minimal case i built and it worked. But in the real case, which handles various async tasks, the test timeouts with the addition of |
Alright, i took the time to try to understand what useFakeTimers do, i was hesitant to use it because its big impact on all async tasks. So far it turns out that i might need to refactor my tests. The example goes like this it('run test without importing a file after it', async () => {
const { getByText } = render(<App />);
await act(async () => {});
getByText('Go to Screen B');
}); The changes i think necessary involves removing the asynchronous test. No more async function for jest.useFakeTimers();
it('run test without importing a file after it', () => {
const { getByText } = render(<App />);
act(() => jest.runAllTimers()); // In the case of an app with side effects on mount,
// this will trigger them in a safe context, rigth?
// in the case of another effects triggered by
// the press of a button, for example,
// i guess this would be neccesary as well.
getByText('Go to Screen B');
}); This line I am now asking if this is the best way to go to fix the issue. Or is there any better alternative? |
Ok, i am closing this as my issue is resolved now, but before doing it, i hit one more problem with the animations of some navigators and the fake timers. I ended up following this comment jestjs/jest#5147 (comment) Maybe this can be of little to someone else. |
@emmarq I was able to resolve this without using fake timers using the mock: jest.mock('@react-navigation/native/lib/commonjs/useLinking.native', () => ({
default: () => ({getInitialState: {then: jest.fn()}}),
__esModule: true,
})); |
Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro. |
Current Behavior
The test succeeds, but the process fails. This is the output:
I haven´t found out why there is this
ReferenceError
. Even disabling linking it still happens.Expected Behavior
The proccess should finish with no error code.
How to reproduce
This is the file with a simple test.
https://github.com/emmarq/RnReplica/blob/main/__tests__/Navigation.test.js
You can look the action with the result.
https://github.com/emmarq/RnReplica/runs/2547893152?check_suite_focus=true
Your Environment
Thank you for the help.
The text was updated successfully, but these errors were encountered: