Permalink
Browse files

refactor: 💡 change RAF set-up for testing

  • Loading branch information...
streamich committed Oct 6, 2018
1 parent 1321a6c commit 8ebeed1dda7735e485b93f73238e783bec7fc196
Showing with 17 additions and 36 deletions.
  1. +3 −0 src/AfterDraf/RAF.ts
  2. +8 −3 src/AfterDraf/__tests__/index.test.tsx
  3. +1 −2 src/AfterDraf/createSingleRunDraf.ts
  4. +5 −31 yarn.lock
View
@@ -0,0 +1,3 @@
const RAF = typeof window === 'object' ? requestAnimationFrame : () => {};
export default RAF as (callback: (...args) => any) => any;
@@ -1,13 +1,18 @@
import {createElement as h} from 'react';
import {render} from 'react-dom';
import {AfterDraf} from '..';
import RAF from '../RAF';
try {
(window as any).requestAnimationFrame = (callback) => setTimeout(callback, 17);
} catch {}
jest.mock('../RAF');
const RAFMock = RAF as any as jest.SpyInstance;
const sleep = (time) => new Promise((resolve) => setTimeout(resolve, time));
beforeEach(() => {
RAFMock.mockClear();
RAFMock.mockImplementation(cb => setImmediate(cb, 17));
});
describe('<AfterDraf>', () => {
it('default <AfterDraf> exists', () => {
expect(typeof AfterDraf).toBe('function');
@@ -1,5 +1,6 @@
import * as React from 'react';
import {isClient} from '../util';
import RAF from './RAF';
export interface IAfterDrafState {
ready: boolean;
@@ -25,8 +26,6 @@ export const createSingleRunDraf = isClient
componentDidMount () {
if (!signelDrafFinished) {
const RAF = requestAnimationFrame;
this.frame = RAF(() => {
this.frame = RAF(() => {
signelDrafFinished = true;
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

1 comment on commit 8ebeed1

@streamich

This comment has been minimized.

Show comment
Hide comment
@streamich

streamich Oct 6, 2018

Owner

Build version: 2.2.0-fix-typing.113 🤞 fix-typing on Travis 🎉

Owner

streamich commented on 8ebeed1 Oct 6, 2018

Build version: 2.2.0-fix-typing.113 🤞 fix-typing on Travis 🎉

Please sign in to comment.