Skip to content

Commit

Permalink
[Tests]: add useState test case in mount for react hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
chenesan committed Feb 28, 2019
1 parent cafa8c7 commit 9faac9d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/enzyme-test-suite/test/ReactWrapper-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 {
describeWithDOM,
Expand Down Expand Up @@ -1660,6 +1661,34 @@ describeWithDOM('mount', () => {
});
});
});

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

const wrapper = mount(<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 = mount(<ComponentUsingStateHook />);
const div = wrapper.find('div');
const setCount = div.prop('onClick');
setCount();

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

describe('.findWhere(predicate)', () => {
Expand Down

0 comments on commit 9faac9d

Please sign in to comment.