Skip to content

Commit fe712fe

Browse files
thavelickclaude
andcommitted
Optimize showSaveMessage test with Jest fake timers
Replace 2+ second setTimeout with jest.advanceTimersByTime(2000) for instant test execution. Improves test performance by ~70% (2.8s → 0.86s Jest time). 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent e8a5f47 commit fe712fe

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

tests/search.spec.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,15 @@ describe("Settings Functions", () => {
767767
});
768768

769769
describe("showSaveMessage", () => {
770-
test("shows and hides save message", (done) => {
770+
beforeEach(() => {
771+
jest.useFakeTimers();
772+
});
773+
774+
afterEach(() => {
775+
jest.useRealTimers();
776+
});
777+
778+
test("shows and hides save message", () => {
771779
const mockMessage = {
772780
classList: {
773781
add: jest.fn(),
@@ -784,10 +792,9 @@ describe("Settings Functions", () => {
784792

785793
expect(mockMessage.classList.add).toHaveBeenCalledWith("visible");
786794

787-
setTimeout(() => {
788-
expect(mockMessage.classList.remove).toHaveBeenCalledWith("visible");
789-
done();
790-
}, 2100);
795+
jest.advanceTimersByTime(2000);
796+
797+
expect(mockMessage.classList.remove).toHaveBeenCalledWith("visible");
791798
});
792799

793800
test("handles missing message element gracefully", () => {

0 commit comments

Comments
 (0)