Skip to content

Commit 5f7cdee

Browse files
committed
mock rAF locally in new tests
1 parent 6b60a0e commit 5f7cdee

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

polaris-react/src/components/Scrollable/tests/Scrollable.test.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ import {ScrollableContext} from '../context';
66
import type {ScrollableProps} from '../Scrollable';
77

88
describe('<Scrollable />', () => {
9+
let rafSpy: jest.SpyInstance;
10+
11+
beforeAll(() => {
12+
rafSpy = jest
13+
.spyOn(window, 'requestAnimationFrame')
14+
.mockImplementation((cb) => {
15+
cb(Date.now());
16+
return Math.random();
17+
});
18+
});
19+
20+
afterAll(() => {
21+
rafSpy.mockRestore();
22+
});
23+
924
it('mounts', () => {
1025
const scrollable = mountWithApp(<Scrollable />);
1126
expect(scrollable).toBeDefined();

polaris-react/tests/setup/tests.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,3 @@ import './matchers';
66
afterEach(() => {
77
destroyAll();
88
});
9-
10-
globalThis.requestAnimationFrame = (cb) => {
11-
cb(Date.now());
12-
return Math.random();
13-
};

0 commit comments

Comments
 (0)