Skip to content

Commit

Permalink
use mock requestAnimationFrame to replace delay
Browse files Browse the repository at this point in the history
Signed-off-by: tygao <tygao@amazon.com>
  • Loading branch information
raintygao committed Jun 7, 2024
1 parent 7ac58cf commit 40ea8ed
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions public/hooks/use_patch_fixed_style.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ describe('usePatchFixedStyle hook', () => {
},
},
});
jest.spyOn(window, 'requestAnimationFrame').mockImplementation((cb) => cb());
});

afterEach(() => {
jest.clearAllMocks();
window.requestAnimationFrame.mockRestore();
});

it('should patch corresponding left style when sidecarConfig$ pipe', async () => {
Expand All @@ -43,7 +45,6 @@ describe('usePatchFixedStyle hook', () => {
paddingSize: 300,
})
);
await new Promise((r) => setTimeout(r, 2000));

expect(document.head).toMatchSnapshot();
});
Expand All @@ -56,7 +57,6 @@ describe('usePatchFixedStyle hook', () => {
paddingSize: 300,
})
);
await new Promise((r) => setTimeout(r, 2000));

expect(document.head).toMatchSnapshot();
});
Expand All @@ -70,7 +70,6 @@ describe('usePatchFixedStyle hook', () => {
isHidden: true,
})
);
await new Promise((r) => setTimeout(r, 2000));

expect(document.head).toMatchSnapshot();
});
Expand All @@ -83,7 +82,6 @@ describe('usePatchFixedStyle hook', () => {
paddingSize: 300,
})
);
await new Promise((r) => setTimeout(r, 2000));

expect(document.head).toMatchSnapshot();
});
Expand Down

0 comments on commit 40ea8ed

Please sign in to comment.