mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 17:45:22 +00:00
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:
committed by
David Lechner
parent
bf4670b25d
commit
c733881815
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user