From 9a621f717db194656c8be899dbcbdff06b5a4229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B3=E4=B9=99=E5=B1=B1?= Date: Tue, 29 Jan 2019 16:42:59 +0800 Subject: [PATCH] [Tests] more `useState` --- .../test/shared/hooks/useState.jsx | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/enzyme-test-suite/test/shared/hooks/useState.jsx b/packages/enzyme-test-suite/test/shared/hooks/useState.jsx index 91523f32c..2f5e87ef0 100644 --- a/packages/enzyme-test-suite/test/shared/hooks/useState.jsx +++ b/packages/enzyme-test-suite/test/shared/hooks/useState.jsx @@ -55,6 +55,33 @@ export default function describeUseState({ expect(wrapper.find('.counter').text()).to.equal(String(initialCount - 1)); }); + it('handles useState', () => { + function ComponentUsingStateHook() { + const [count] = useState(0); + return
{count}
; + } + + const wrapper = Wrap(); + + expect(wrapper.find('div').length).to.equal(1); + expect(wrapper.find('div').text()).to.equal('0'); + }); + + it('handles setState returned from useState', () => { + function ComponentUsingStateHook() { + const [count, setCount] = useState(0); + return
setCount(count + 1)}>{count}
; + } + + const wrapper = Wrap(); + const div = wrapper.find('div'); + const setCount = div.prop('onClick'); + setCount(); + wrapper.update(); + + expect(wrapper.find('div').text()).to.equal('1'); + }); + describe('useState with willReceive prop effect / simulate getDerivedStateFromProp', () => { const newPropCount = 10;