Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. Reducers ---test---
  2.  
  3. import loginReducer from '../reducers/loginReducer';
  4. import * as types from '../actions/types';
  5.  
  6. const initialState = {
  7. message: '',
  8. user: {},
  9. status: 'none',
  10. };
  11.  
  12. const responsedata_success = {
  13. user: {
  14. email: 'testuser@email.com',
  15. username: 'testuser',
  16. token: 'user-token',
  17. },
  18. };
  19.  
  20. const responsedata_failure = {
  21. errors: {
  22. error: ['A user with this email and password was not found.'],
  23. },
  24. };
  25.  
  26.  
  27. describe('Login reducer', () => {
  28. it('should return the initial state', () => {
  29. expect(loginReducer(initialState, {})).toEqual(initialState);
  30. });
  31.  
  32. it('should handle LOGIN_SUCCESS', () => {
  33. expect(loginReducer(initialState, {
  34. type: types.LOGIN_SUCCESS,
  35. payload: responsedata_success,
  36. })).toEqual(
  37. {
  38. message: responsedata_success,
  39. status: 'loading',
  40. user: {},
  41. },
  42. );
  43. });
  44.  
  45. it('should handle LOGIN_FAILURE', () => {
  46. expect(loginReducer(initialState, {
  47. type: types.LOGIN_FAILURE,
  48. payload: responsedata_failure,
  49. })).toEqual(
  50. {
  51. message: responsedata_failure.errors,
  52. status: 'error',
  53. user: {},
  54. },
  55. );
  56. });
  57. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement