Guest User

Untitled

a guest
Dec 16th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. import { combineReducers } from 'redux';
  2. import { string, number } from 'prop-types';
  3. import { connect } from 'react-redux';
  4. import { flow, createStore, modifyStore, mount, dispatch, getState, wrapper } from '../index';
  5. import setIn from '../../set-in';
  6. import { simpleFunc2, simpleFunc1 } from '../bdd';
  7.  
  8. // --- test data ---
  9.  
  10. const initialCatState = { isLoading: true };
  11. const SET_AGE = 'SET_AGE';
  12. const setAge = age => ({ payload: age, type: SET_AGE });
  13. const catReducer = (state = initialCatState, { type, payload }) => {
  14. if (type === SET_AGE) return { ...state, age: payload };
  15. return state;
  16. };
  17. const reducers = combineReducers({
  18. cat: catReducer
  19. });
  20. const middlewares = [];
  21. const Cat = ({ name, age }) => (
  22. <div>
  23. <h1>{ name }</h1>
  24. <span>age: { age }</span>
  25. </div>
  26. );
  27. Cat.propTypes = {
  28. name: string.isRequired,
  29. age: number.isRequired
  30. };
  31. const CatContainer = connect(({ cat }) => ({
  32. name: cat.name,
  33. age: cat.age
  34. }));
  35.  
  36. // --- begin test ---
  37.  
  38. const modifyCat = ({ store }) => setIn(store, 'cat', { name: 'Barsik', age: 5 });
  39.  
  40. describe('bdd tests', () => {
  41. it('should create and modify', () => {
  42. flow([simpleFunc1(), simpleFunc2()]);
  43.  
  44. // expect(2).tobe(3);
  45.  
  46. flow(
  47. createStore(reducers, middlewares),
  48. modifyStore(modifyCat),
  49. mount(CatContainer),
  50. getWrapper(wrapper => expect(wrapper.toMatchSnapshot())),
  51. dispatch(setAge(6)),
  52. getWrapper(wrapper => expect(wrapper).toMatchSnapshot()),
  53. expect(getActions()).toMatchSnapshot(),
  54. expect(getState()).toMatchSnapshot()
  55. );
  56. });
  57. });
Add Comment
Please, Sign In to add comment