fix some test console errors

The react testing library prints errors to the console about not using
act(). This adds fixes/workarounds for most cases.
This commit is contained in:
David Lechner
2023-05-17 16:33:47 -05:00
committed by David Lechner
parent bf4670b25d
commit c733881815
6 changed files with 51 additions and 11 deletions
+13
View File
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022-2023 The Pybricks Authors
import { AbstractPureComponent2 } from '@blueprintjs/core';
import { act, cleanup, getByLabelText, waitFor } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../test';
@@ -8,6 +9,18 @@ import { firmwareInstallPybricks } from '../firmware/actions';
import { firmwareRestoreOfficialDialogShow } from '../firmware/restoreOfficialDialog/actions';
import Settings from './Settings';
beforeEach(() => {
// this avoids react testing lib errors about not using act() by running
// callbacks immediately instead of deferring
jest.spyOn(
AbstractPureComponent2.prototype,
'requestAnimationFrame',
).mockImplementation((callback) => {
callback();
return () => undefined;
});
});
afterEach(() => {
cleanup();
jest.resetAllMocks();