Skip to content

Commit

Permalink
[Tests] more useState
Browse files Browse the repository at this point in the history
  • Loading branch information
chenesan authored and ljharb committed Jan 29, 2019
1 parent 5d635e1 commit 9a621f7
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/enzyme-test-suite/test/shared/hooks/useState.jsx
Expand Up @@ -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 <div>{count}</div>;
}

const wrapper = Wrap(<ComponentUsingStateHook />);

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 <div onClick={() => setCount(count + 1)}>{count}</div>;
}

const wrapper = Wrap(<ComponentUsingStateHook />);
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;

Expand Down

0 comments on commit 9a621f7

Please sign in to comment.