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 28, 2019
1 parent 9faac9d commit dee77bd
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
forwardRef,
memo,
PureComponent,
useState,
} from './_helpers/react-compat';
import {
describeIf,
Expand Down Expand Up @@ -1534,6 +1535,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 dee77bd

Please sign in to comment.