Skip to content

Commit

Permalink
Merge pull request #9952 from marmelab/fix-flaky-tests
Browse files Browse the repository at this point in the history
Fix flaky tests
  • Loading branch information
fzaninotto authored Jun 26, 2024
2 parents d9f1419 + 7955d97 commit 060d38e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
9 changes: 9 additions & 0 deletions packages/create-react-admin/src/generateAppTestFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ test("should pass", async () => {
? `
// Sign in
// Ensure the form is fully loaded before interacting with it
await new Promise((resolve) => setTimeout(resolve, 1000));
fireEvent.change(await screen.findByLabelText("Username *"), {
target: { value: "janedoe" },
});
Expand All @@ -33,6 +36,9 @@ test("should pass", async () => {
// Open the first post
fireEvent.click(await screen.findByText("Post 1"));
fireEvent.click(await screen.findByText("Edit"));
await screen.findByDisplayValue("Post 1");
// Ensure the form is fully loaded before interacting with it
await new Promise((resolve) => setTimeout(resolve, 1000));
// Update its title
fireEvent.change(await screen.findByDisplayValue("Post 1"), {
target: { value: "Post 1 edited" },
Expand All @@ -45,6 +51,9 @@ test("should pass", async () => {
// Open the first comment
fireEvent.click(await screen.findByText("Comment 1"));
fireEvent.click(await screen.findByText("Edit"));
await screen.findByDisplayValue("Post 1 edited");
// Ensure the form is fully loaded before interacting with it
await new Promise((resolve) => setTimeout(resolve, 1000));
// Edit the comment selected post
fireEvent.click(await screen.findByDisplayValue("Post 1 edited"));
fireEvent.click(await screen.findByText("Post 11"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const SuccessCase = () => {
const index = posts.findIndex(p => p.id === params.id);
posts.splice(index, 1);
resolve({ data: params.previousData });
}, 1000);
}, 500);
});
},
} as any;
Expand Down Expand Up @@ -94,7 +94,7 @@ export const ErrorCase = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
reject(new Error('something went wrong'));
}, 1000);
}, 500);
});
},
} as any;
Expand Down
8 changes: 4 additions & 4 deletions packages/ra-core/src/dataProvider/useDelete.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,16 @@ describe('useDelete', () => {
screen.getByText('Delete first post').click();
await waitFor(() => {
expect(screen.queryByText('success')).toBeNull();
expect(screen.queryByText('Hello')).not.toBeNull();
expect(screen.queryByText('World')).not.toBeNull();
expect(screen.queryByText('mutating')).not.toBeNull();
});
expect(screen.queryByText('Hello')).not.toBeNull();
expect(screen.queryByText('World')).not.toBeNull();
await waitFor(() => {
expect(screen.queryByText('success')).not.toBeNull();
expect(screen.queryByText('Hello')).toBeNull();
expect(screen.queryByText('World')).not.toBeNull();
expect(screen.queryByText('mutating')).toBeNull();
});
expect(screen.queryByText('Hello')).toBeNull();
expect(screen.queryByText('World')).not.toBeNull();
});
it('when pessimistic, displays error and error side effects when dataProvider promise rejects', async () => {
jest.spyOn(console, 'log').mockImplementation(() => {});
Expand Down

0 comments on commit 060d38e

Please sign in to comment.