diff --git a/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx b/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx index 85b9a8eef..f511ee28d 100644 --- a/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx +++ b/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx @@ -30,6 +30,7 @@ import { PureComponent, Suspense, useEffect, + useLayoutEffect, useState, } from './_helpers/react-compat'; import { @@ -973,7 +974,7 @@ describeWithDOM('mount', () => { setCtr(1); setTimeout(() => { setCtr(2); - }, 1e3); + }, 100); }, []); return (
@@ -997,7 +998,41 @@ describeWithDOM('mount', () => {
`); done(); - }, 1e3); + }, 100); + }); + + it('works with `useLayoutEffect`', (done) => { + function ComponentUsingLayoutEffectHook() { + const [ctr, setCtr] = useState(0); + useLayoutEffect(() => { + setCtr(1); + setTimeout(() => { + setCtr(2); + }, 100); + }, []); + return ( +
+ {ctr} +
+ ); + } + const wrapper = mount(); + + expect(wrapper.debug()).to.equal(` +
+ 1 +
+
`); + + setTimeout(() => { + wrapper.update(); + expect(wrapper.debug()).to.equal(` +
+ 2 +
+
`); + done(); + }, 100); }); }); diff --git a/packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx b/packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx index 49066f832..254c27df9 100644 --- a/packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx +++ b/packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx @@ -27,6 +27,7 @@ import { PureComponent, Suspense, useEffect, + useLayoutEffect, useState, Profiler, memo, @@ -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 ( +
+ {ctr} +
+ ); + } + const wrapper = shallow(); + + expect(wrapper.debug()).to.equal(`
+ 1 +
`); + + setTimeout(() => { + wrapper.update(); + expect(wrapper.debug()).to.equal(`
+ 2 +
`); + done(); + }, 100); + }); + + // TODO: enable when https://github.com/facebook/react/issues/15275 is fixed + it.skip('works with `useLayoutEffect`', (done) => { + function ComponentUsingEffectHook() { + const [ctr, setCtr] = useState(0); + useLayoutEffect(() => { + setCtr(1); + setTimeout(() => { + setCtr(2); + }, 100); }, []); return (
@@ -1157,7 +1189,7 @@ describe('shallow', () => { 2
`); done(); - }, 1e3); + }, 100); }); });