Files
pybricks-code/src/alerts/UnexpectedErrorAlert.test.tsx
T
David Lechner d88ce8998f 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.
2023-03-10 18:16:27 -06:00

20 lines
666 B
TypeScript

// SPDX-License-Identifier: MIT
// Copyright (c) 2022-2023 The Pybricks Authors
import { Toast } from '@blueprintjs/core';
import { act } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../test';
import { unexpectedError } from './UnexpectedErrorAlert';
it('should dismiss when close is clicked', async () => {
const callback = jest.fn();
const toast = unexpectedError(callback, { error: new Error('test') });
const [user, message] = testRender(<Toast {...toast} />);
await act(() => user.click(message.getByRole('button', { name: /close/i })));
expect(callback).toHaveBeenCalledWith('dismiss');
});