Advertisement
Guest User

Untitled

a guest
Jan 25th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. class LoginPage extends Component {
  2. constructor(props) {
  3. super(props);
  4. this.state = {
  5. username: '',
  6. password: ''
  7. };
  8.  
  9. this.handleChange = this.handleChange.bind(this);
  10.  
  11. ...
  12. }
  13.  
  14. handleChange(event) {
  15. this.setState({[event.target.name]: event.target.value})
  16. }
  17.  
  18. ...
  19.  
  20. return(
  21. ...
  22. <TextField name='username' onChange={this.handleChange} />
  23. )
  24.  
  25. it('handles change', () => {
  26. const spy = sinon.spy(LoginPage.prototype, 'handleChange');
  27. const _wrapper = shallow(<LoginPage />);
  28.  
  29. spy({
  30. event: {
  31. target: {
  32. name: 'username',
  33. value: 'password'
  34. }
  35. }
  36. }
  37. );
  38.  
  39. expect(_wrapper.state().username).to.equal('username');
  40. expect(_wrapper.state().password).to.equal('password')
  41. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement