Advertisement
Guest User

Untitled

a guest
Feb 4th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import logo from './logo.svg';
  3. import './App.css';
  4.  
  5. class App extends Component {
  6. constructor() {
  7. super();
  8. this.onSubmitDetails = this.onSubmitDetails.bind(this);
  9. };
  10.  
  11. onSubmitDetails(event) {
  12. event.preventDefault();
  13. alert("Hey! Form submitted??")
  14. }
  15. render() {
  16. return (
  17. <div className="App">
  18. <form onSubmit={this.onSubmitDetails}>
  19. <input type="text" className="loginBox" placeholder="Username"
  20. required="required"/>
  21. <input type="password" className="loginBox" placeholder="Password" required="required"/>
  22. <input type="submit" className="loginBox submit" value="SIGN IN"/>
  23. </form>
  24. </div>
  25. );
  26. }
  27. }
  28.  
  29. export default App;
  30.  
  31. import 'jsdom-global/register';
  32. import React from 'react';
  33. import ReactDOM from 'react-dom';
  34. import { shallow, mount } from "enzyme";
  35. import expect from 'expect';
  36. import sinon from 'sinon';
  37. import App from './App';
  38.  
  39. describe("Component: LoginContainer", () => {
  40. it('should login', () => {
  41. const props = {
  42. fields: {
  43. user: {
  44. username: {},
  45. password: {}
  46. }
  47. },
  48. onSubmitDetails: () => {}
  49. };
  50. const onSubmitDetails = sinon.spy();
  51. const wrapper = mount(<LoginContainer />);
  52.  
  53. const username = wrapper.find('.loginBox').get(0);
  54. username.value = 'abc';
  55. expect(username.value).toEqual('abc');
  56.  
  57. const password = wrapper.find('.loginBox').get(1);
  58. password.value = 'xyz';
  59. expect(password.value).toEqual('xyz');
  60.  
  61. wrapper.find('form').simulate('submit', { preventDefault(){} });
  62. console.log(onSubmitDetails.called); //gives false
  63. });
  64. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement