Skip to content

Commit

Permalink
[Tests]: add useState test case in shallow for hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
chenesan committed Apr 7, 2019
1 parent 2603c22 commit 03318c8
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2012,6 +2012,35 @@ describe('shallow', () => {
});
});

describeIf(is('>= 16.8'), 'hooks', () => {
it('handles useState', () => {
const ComponentUsingStateHook = () => {
const [count] = 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] = 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 03318c8

Please sign in to comment.