Skip to content

Commit

Permalink
Add a test for enzymejs#1765
Browse files Browse the repository at this point in the history
  • Loading branch information
koba04 committed Aug 17, 2018
1 parent fb72d99 commit 8d4b304
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 @@ -5084,6 +5084,36 @@ describe('shallow', () => {
expect(spy).to.have.property('callCount', 0);
});

it('should be able to call `componentDidMount` directly when disableLifecycleMethods is true', () => {
class Table extends React.Component {
render() {
return (<table />);
}
}

class MyComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
showTable: false,
};
}

componentDidMount() {
this.setState({ showTable: true });
}

render() {
const { showTable } = this.state;
return (<React.Fragment>{showTable ? <Table /> : null}</React.Fragment>);
}
}
const wrapper = shallow(<MyComponent />, { disableLifecycleMethods: true });
expect(wrapper.find(Table).length).to.equal(0);
wrapper.instance().componentDidMount();
expect(wrapper.find(Table).length).to.equal(1);
});

it('should call shouldComponentUpdate when disableLifecycleMethods flag is true', () => {
const spy = sinon.spy();
class Foo extends React.Component {
Expand Down

0 comments on commit 8d4b304

Please sign in to comment.