Skip to content

Commit

Permalink
Merge pull request #92 from happo/cancel-animation-frame
Browse files Browse the repository at this point in the history
Stop no-op:ing cancelAnimationFrame
  • Loading branch information
trotzig committed Aug 8, 2019
2 parents 1bf3b72 + 0d88baf commit 4ebbbd4
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/JSDOMDomProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default class JSDOMDomProvider {
availHeight: { value: height },
});
win.requestAnimationFrame = (callback) => setTimeout(callback, 0);
win.cancelAnimationFrame = () => {};
win.cancelAnimationFrame = clearTimeout;
},
},
jsdomOptions,
Expand Down
38 changes: 38 additions & 0 deletions test/integrations/examples/Foo-react-happo.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,41 @@ export const themedExampleAsync = (renderInDom) => {
);
return new Promise((resolve) => setTimeout(resolve, 20));
};

class RAFExample extends React.Component {
async componentDidMount() {
window.requestAnimationFrame(() => {
this.setState({ label: 'Loaded' });
});
}

render() {
if (!this.state) {
return null;
}
return <div>{this.state.label}</div>;
}
}

export const rafExample = () => <RAFExample />;

class RAFUnmountExample extends React.Component {
async componentDidMount() {
this.raf = window.requestAnimationFrame(() => {
document.title = 'Foobar';
});
}

componentWillUnmount() {
window.cancelAnimationFrame(this.raf);
}

render() {
if (!this.state) {
return <div>Not loaded</div>;
}
return <div>{this.state.label}</div>;
}
}

export const rafUnmountExample = () => <RAFUnmountExample />;
14 changes: 13 additions & 1 deletion test/integrations/react-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ it('produces the right html', async () => {
html: '<button>I am dark</button>',
variant: 'themedExampleAsync',
},
{
component: 'Foo-react',
css: '',
html: '<div>Loaded</div>',
variant: 'rafExample',
},
{
component: 'Foo-react',
css: '',
html: '<div>Not loaded</div>',
variant: 'rafUnmountExample',
},
{
component: 'Foo-react',
css: '',
Expand Down Expand Up @@ -175,7 +187,7 @@ describe('with the puppeteer plugin', () => {

it('produces the right number of snaps', async () => {
await subject();
expect(config.targets.chrome.snapPayloads.length).toBe(16);
expect(config.targets.chrome.snapPayloads.length).toBe(18);
});
});

Expand Down

0 comments on commit 4ebbbd4

Please sign in to comment.