Skip to content

Instantly share code, notes, and snippets.

@alirezamirian
Last active February 22, 2019 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alirezamirian/ae3ad5a42aa19a77d0b97b6a8c9fe1dd to your computer and use it in GitHub Desktop.
Save alirezamirian/ae3ad5a42aa19a77d0b97b6a8c9fe1dd to your computer and use it in GitHub Desktop.
it('should work in controlled mode', () => {
class ControlledUsage extends React.Component<{}, { counter: number, open: boolean }> {
constructor(props) {
super(props);
this.toggle = this.toggle.bind(this);
}
state = {
counter: 0,
open: true,
};
toggle(value: boolean) {
if (this.state.counter < 2) {
this.setState(state => ({
open: !state.open,
counter: state.counter + 1,
}));
}
}
render(): React.ReactNode {
return <Zippy header={'header'}
open={this.state.open} onToggle={this.toggle}/>;
}
}
const { clickHeader, isOpen } = mountUsage(<ControlledUsage/>);
expect(isOpen()).toEqual(true);
clickHeader();
expect(isOpen()).toEqual(false);
clickHeader();
expect(isOpen()).toEqual(true);
clickHeader();
expect(isOpen()).toEqual(true);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment