cozy-drive
cozy-drive copied to clipboard
FilesViewer - Flaky test
Lately we have trouble with the CI because of a flaky test. I put it in quarantine until I can fix it (cf: commit). This issue aims to follow the resolution of this problem.
Error traces
FAIL src/drive/web/modules/viewer/FilesViewer.spec.jsx
● FilesViewer › should fetch more files if necessary
This test called the console which is forbidden.
Here is what have been logged:
console.error
Warning: An update to %s inside a test was not wrapped in act(...).
When testing, code that causes React state updates should be wrapped into act(...):
act(() => {
/\* fire events that update state \*/
});
/\* assert on the output \*/
This ensures that you're testing the behavior the user would see in the browser. Learn more at https://fb.me/react-wrap-tests-with-act%s FilesViewer
in FilesViewer
in FabProvider (created by AppLike)
in BreakpointsProvider (created by AppLike)
in ThumbnailSizeContextProvider (created by AppLike)
in AcceptingSharingProvider (created by AppLike)
in I18n (created by TestI18n)
in TestI18n (created by AppLike)
in CozyProvider (created by AppLike)
in Provider (created by AppLike)
in AppLike (created by WrapperComponent)
in WrapperComponent
If calling the console is normal in your test case, consider mocking the console as is:
jest.spyOn(console, 'method').mockImplementation();
afterEach(() => {
if (consoleCalls.length > 0) {
throw new Error(
^
red(\`
This test called the console which is forbidden.
at Object.<anonymous> (jestHelpers/ConsoleUsageReporter.js:109:15)
Normally converting enzyme to react-testing-library fix this issue (cf: commit)
There is stil a flaky test in FilesViewer. The error comes from the number of calls to the jest.fn() function in the fetchMore test. When you run the test file alone there is no problem but as soon as it is with all the tests it can cause a problem