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