Skip to content

Commit 78a93cd

Browse files
committed
fix(tests): ensure SaveMarkdownModal tests wait for async state updates
The tests were causing unhandled rejection errors because they weren't waiting for the `finally` block's `setSaving(false)` to complete after error handling. Updated waitFor assertions to also check that the save button text returns to "Save" (from "Saving..."), ensuring all async state updates are complete before the test ends and the component unmounts.
1 parent 02eed05 commit 78a93cd

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/__tests__/renderer/components/SaveMarkdownModal.test.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,11 @@ describe('SaveMarkdownModal', () => {
378378
fireEvent.click(saveButton);
379379
});
380380

381+
// Wait for both the error to appear AND saving state to reset (from finally block)
381382
await waitFor(() => {
382383
expect(screen.getByText('Failed to save file')).toBeInTheDocument();
384+
// Ensure the save button is back to "Save" (not "Saving...") to confirm finally block completed
385+
expect(screen.getByRole('button', { name: 'Save' })).toBeInTheDocument();
383386
});
384387
});
385388

@@ -395,8 +398,11 @@ describe('SaveMarkdownModal', () => {
395398
fireEvent.click(saveButton);
396399
});
397400

401+
// Wait for both the error to appear AND saving state to reset (from finally block)
398402
await waitFor(() => {
399403
expect(screen.getByText('Permission denied')).toBeInTheDocument();
404+
// Ensure the save button is back to "Save" (not "Saving...") to confirm finally block completed
405+
expect(screen.getByRole('button', { name: 'Save' })).toBeInTheDocument();
400406
});
401407
});
402408

@@ -521,8 +527,10 @@ describe('SaveMarkdownModal', () => {
521527
fireEvent.click(saveButton);
522528
});
523529

530+
// Wait for both the error to appear AND saving state to reset (from finally block)
524531
await waitFor(() => {
525532
expect(screen.getByText('Failed to save file')).toBeInTheDocument();
533+
expect(screen.getByRole('button', { name: 'Save' })).toBeInTheDocument();
526534
});
527535

528536
// Change folder
@@ -544,8 +552,10 @@ describe('SaveMarkdownModal', () => {
544552
fireEvent.click(saveButton);
545553
});
546554

555+
// Wait for both the error to appear AND saving state to reset (from finally block)
547556
await waitFor(() => {
548557
expect(screen.getByText('Failed to save file')).toBeInTheDocument();
558+
expect(screen.getByRole('button', { name: 'Save' })).toBeInTheDocument();
549559
});
550560

551561
// Change filename

0 commit comments

Comments
 (0)