test: wrap all user calls in act()

Some user events trigger react dom changes. These need to be wrapped in
act() to avoid a warning printed to the console. To be save, we wrap
all instances.
This commit is contained in:
David Lechner
2023-03-10 18:16:27 -06:00
committed by David Lechner
parent 78290eb927
commit d88ce8998f
42 changed files with 212 additions and 172 deletions
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors
// Copyright (c) 2022-2023 The Pybricks Authors
import { cleanup } from '@testing-library/react';
import { act, cleanup } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../../../test';
import { toggleBluetooth } from '../../../ble/actions';
@@ -16,7 +16,7 @@ it('should dispatch action when clicked', async () => {
<BluetoothButton id="test-bluetooth-button" />,
);
await user.click(button.getByRole('button', { name: 'Bluetooth' }));
await act(() => user.click(button.getByRole('button', { name: 'Bluetooth' })));
expect(dispatch).toHaveBeenCalledWith(toggleBluetooth());
});
+3 -3
View File
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors
// Copyright (c) 2022-2023 The Pybricks Authors
import { cleanup } from '@testing-library/react';
import { act, cleanup } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../../../test';
import { repl } from '../../../hub/actions';
@@ -17,7 +17,7 @@ it('should dispatch action when clicked', async () => {
hub: { hasRepl: true, runtime: HubRuntimeState.Idle },
});
await user.click(button.getByRole('button', { name: 'REPL' }));
await act(() => user.click(button.getByRole('button', { name: 'REPL' })));
expect(dispatch).toHaveBeenCalledWith(repl(false));
});
+3 -3
View File
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors
// Copyright (c) 2022-2023 The Pybricks Authors
import { cleanup } from '@testing-library/react';
import { act, cleanup } from '@testing-library/react';
import React from 'react';
import { testRender, uuid } from '../../../../test';
import { FileFormat } from '../../../ble-pybricks-service/protocol';
@@ -22,7 +22,7 @@ it('should dispatch action when clicked', async () => {
},
});
await user.click(button.getByRole('button', { name: 'Run' }));
await act(() => user.click(button.getByRole('button', { name: 'Run' })));
expect(dispatch).toHaveBeenCalledWith(downloadAndRun(FileFormat.MultiMpy6, false));
});
+3 -3
View File
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors
// Copyright (c) 2022-2023 The Pybricks Authors
import { cleanup } from '@testing-library/react';
import { act, cleanup } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../../../test';
import { stop } from '../../../hub/actions';
@@ -17,7 +17,7 @@ it('should dispatch action when clicked', async () => {
hub: { runtime: HubRuntimeState.Running },
});
await user.click(button.getByRole('button', { name: 'Stop' }));
await act(() => user.click(button.getByRole('button', { name: 'Stop' })));
expect(dispatch).toHaveBeenCalledWith(stop());
});