Skip to content

Commit

Permalink
[Tests]: add failed useState test case in shallow for hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
chenesan committed Feb 7, 2019
1 parent 7711693 commit 9f3439a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
Expand Up @@ -1526,6 +1526,34 @@ describe('shallow', () => {
});
});

describeIf(is('>= 16.8'), 'hooks', () => {
it('handles useState', () => {
const ComponentUsingStateHook = () => {
const [count] = React.useState(0);
return <div>{count}</div>;
};

const wrapper = shallow(<ComponentUsingStateHook />);

expect(wrapper.find('div').length).to.equal(1);
expect(wrapper.find('div').text()).to.equal('0');
});
it('handles setState returned from useState', () => {
const ComponentUsingStateHook = () => {
const [count, setCount] = React.useState(0);
return <div onClick={() => setCount(count + 1)}>{count}</div>;
};

const wrapper = shallow(<ComponentUsingStateHook />);
const div = wrapper.find('div');
const setCount = div.prop('onClick');
setCount();
wrapper.update();

expect(wrapper.find('div').text()).to.equal('1');
});
});

describeWithDOM('find DOM elements by constructor', () => {
const { elements, all } = getData();

Expand Down

0 comments on commit 9f3439a

Please sign in to comment.