Skip to content

Commit

Permalink
Add skipped tests of useLayoutEffect for shallow
Browse files Browse the repository at this point in the history
Once the [shallow renderer can run useEffect](facebook/react#15275) we should reopen these tests.
  • Loading branch information
chenesan committed May 11, 2019
1 parent ef737c7 commit 3d0983b
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
PureComponent,
Suspense,
useEffect,
useLayoutEffect,
useState,
Profiler,
memo,
Expand Down Expand Up @@ -1131,13 +1132,44 @@ describe('shallow', () => {
describeIf(is('>= 16.8.5'), 'hooks', () => {
// TODO: enable when the shallow renderer fixes its bug
it.skip('works with `useEffect`', (done) => {
function ComponentUsingEffectHook() {
function ComponentUsingLayoutEffectHook() {
const [ctr, setCtr] = useState(0);
useEffect(() => {
setCtr(1);
setTimeout(() => {
setCtr(2);
}, 1e3);
}, 100);
}, []);
return (
<div>
{ctr}
</div>
);
}
const wrapper = shallow(<ComponentUsingLayoutEffectHook />);

expect(wrapper.debug()).to.equal(`<div>
1
</div>`);

setTimeout(() => {
wrapper.update();
expect(wrapper.debug()).to.equal(`<div>
2
</div>`);
done();
}, 100);
});

// TODO: enable when the shallow renderer fixes its bug
it.skip('works with `useLayoutEffect`', (done) => {
function ComponentUsingEffectHook() {
const [ctr, setCtr] = useState(0);
useLayoutEffect(() => {
setCtr(1);
setTimeout(() => {
setCtr(2);
}, 100);
}, []);
return (
<div>
Expand All @@ -1157,7 +1189,7 @@ describe('shallow', () => {
2
</div>`);
done();
}, 1e3);
}, 100);
});
});

Expand Down

0 comments on commit 3d0983b

Please sign in to comment.