diff --git a/src/raf.ts b/src/raf.ts index 1298d21b..0e5f7d49 100644 --- a/src/raf.ts +++ b/src/raf.ts @@ -44,8 +44,12 @@ const wrapperRaf = (callback: () => void, times = 1): number => { wrapperRaf.cancel = (id: number) => { const realId = rafIds.get(id); - cleanup(realId); + cleanup(id); return caf(realId); }; +if (process.env.NODE_ENV !== 'production') { + wrapperRaf.ids = () => rafIds; +} + export default wrapperRaf; diff --git a/tests/raf.test.js b/tests/raf.test.js index 5a17076c..e6bfa22d 100644 --- a/tests/raf.test.js +++ b/tests/raf.test.js @@ -20,11 +20,19 @@ describe('raf', () => { it('cancel', done => { let bamboo = false; + // Call some native raf + for (let i = 0; i < 10; i += 1) { + const nativeId = requestAnimationFrame(() => {}); + cancelAnimationFrame(nativeId); + } + const id = raf(() => { bamboo = true; }, 2); + expect(raf.ids().has(id)).toBeTruthy(); raf.cancel(id); + expect(raf.ids().has(id)).toBeFalsy(); requestAnimationFrame(() => { requestAnimationFrame(() => {