Last active
February 22, 2019 19:44
-
-
Save alirezamirian/ae3ad5a42aa19a77d0b97b6a8c9fe1dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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