diff --git a/packages/ra-core/src/controller/button/useDeleteWithConfirmController.spec.tsx b/packages/ra-core/src/controller/button/useDeleteWithConfirmController.spec.tsx index edc777e5547..be5e46d2423 100644 --- a/packages/ra-core/src/controller/button/useDeleteWithConfirmController.spec.tsx +++ b/packages/ra-core/src/controller/button/useDeleteWithConfirmController.spec.tsx @@ -44,7 +44,7 @@ describe('useDeleteWithConfirmController', () => { const button = await screen.findByText('Delete'); fireEvent.click(button); - waitFor(() => expect(receivedMeta).toEqual('metadata'), { + await waitFor(() => expect(receivedMeta).toEqual('metadata'), { timeout: 1000, }); }); diff --git a/packages/ra-core/src/controller/button/useDeleteWithUndoController.spec.tsx b/packages/ra-core/src/controller/button/useDeleteWithUndoController.spec.tsx index 2de9f730efa..7566f0ef203 100644 --- a/packages/ra-core/src/controller/button/useDeleteWithUndoController.spec.tsx +++ b/packages/ra-core/src/controller/button/useDeleteWithUndoController.spec.tsx @@ -3,7 +3,11 @@ import expect from 'expect'; import { Route, Routes } from 'react-router'; import { fireEvent, screen, render, waitFor } from '@testing-library/react'; -import { testDataProvider } from '../../dataProvider'; +import { + testDataProvider, + UndoableMutation, + useTakeUndoableMutation, +} from '../../dataProvider'; import { CoreAdminContext } from '../../core'; import useDeleteWithUndoController, { UseDeleteWithUndoControllerParams, @@ -22,6 +26,12 @@ describe('useDeleteWithUndoController', () => { }), }); + let takeMutation: () => UndoableMutation | void; + const MutationTrigger = () => { + takeMutation = useTakeUndoableMutation(); + return null; + }; + const MockComponent = () => { const { handleDelete } = useDeleteWithUndoController({ record: { id: 1 }, @@ -38,13 +48,20 @@ describe('useDeleteWithUndoController', () => { } /> + ); const button = await screen.findByText('Delete'); fireEvent.click(button); - waitFor(() => expect(receivedMeta).toEqual('metadata'), { + + // Trigger the mutation. + await waitFor(() => new Promise(resolve => setTimeout(resolve, 0))); + const mutation = takeMutation(); + if (mutation) mutation({ isUndo: false }); + + await waitFor(() => expect(receivedMeta).toEqual('metadata'), { timeout: 1000, }); });