Skip to content

Commit abc51d8

Browse files
committed
Fix a failing test not showing up in useDeleteWithUndoController.
1 parent 6cb679c commit abc51d8

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

packages/ra-core/src/controller/button/useDeleteWithUndoController.spec.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import expect from 'expect';
33
import { Route, Routes } from 'react-router';
44
import { fireEvent, screen, render, waitFor } from '@testing-library/react';
55

6-
import { testDataProvider } from '../../dataProvider';
6+
import {
7+
testDataProvider,
8+
UndoableMutation,
9+
useTakeUndoableMutation,
10+
} from '../../dataProvider';
711
import { CoreAdminContext } from '../../core';
812
import useDeleteWithUndoController, {
913
UseDeleteWithUndoControllerParams,
@@ -22,6 +26,12 @@ describe('useDeleteWithUndoController', () => {
2226
}),
2327
});
2428

29+
let takeMutation: () => UndoableMutation | void;
30+
const MutationTrigger = () => {
31+
takeMutation = useTakeUndoableMutation();
32+
return null;
33+
};
34+
2535
const MockComponent = () => {
2636
const { handleDelete } = useDeleteWithUndoController({
2737
record: { id: 1 },
@@ -38,13 +48,20 @@ describe('useDeleteWithUndoController', () => {
3848
<Routes>
3949
<Route path="/" element={<MockComponent />} />
4050
</Routes>
51+
<MutationTrigger />
4152
</CoreAdminContext>
4253
</TestMemoryRouter>
4354
);
4455

4556
const button = await screen.findByText('Delete');
4657
fireEvent.click(button);
47-
waitFor(() => expect(receivedMeta).toEqual('metadata'), {
58+
59+
// Trigger the mutation.
60+
await waitFor(() => new Promise(resolve => setTimeout(resolve, 0)));
61+
const mutation = takeMutation();
62+
if (mutation) mutation({ isUndo: false });
63+
64+
await waitFor(() => expect(receivedMeta).toEqual('metadata'), {
4865
timeout: 1000,
4966
});
5067
});

0 commit comments

Comments
 (0)