Skip to content

Application State

Melissa Stock edited this page Jul 1, 2019 · 1 revision

Direct Shallow Render

  • describe('>>>H O M E --- REACT-REDUX (Shallow + passing the {store} directly)',()=>{
  • const initialState = {output:100}
  • const mockStore = configureStore()
  • let store,container
  • ``
  • beforeEach(()=>{
  • store = mockStore(initialState)
  • container = shallow(<ConnectedHome store={store} /> )
  • })
  • ``
  • it('+++ render the connected(SMART) component', () => {
  • expect(container.length).toEqual(1)
  • });
  • ``
  • it('+++ check Prop matches with initialState', () => {
  • expect(container.prop('output')).toEqual(initialState.output)
  • });
  • ``
  • });

Wrapping the component

  • describe('>>>H O M E --- REACT-REDUX (Mount + wrapping in <Provider>)',()=>{
  • const initialState = {output:10}
  • const mockStore = configureStore()
  • let store,wrapper
  • ``
  • beforeEach(()=>{
  • store = mockStore(initialState)
  • wrapper = mount( <Provider store={store}><ConnectedHome /></Provider> )
  • })
  • ``
  • ``
  • it('+++ render the connected(SMART) component', () => {
  • expect(wrapper.find(ConnectedHome).length).toEqual(1)
  • });
  • ``
  • it('+++ check Prop matches with initialState', () => {
  • expect(wrapper.find(Home).prop('output')).toEqual(initialState.output)
  • });
  • ``
  • it('+++ check action on dispatching ', () => {
  • let action
  • store.dispatch(addInputs(500))
  • store.dispatch(subtractInputs(100))
  • action = store.getActions()
  • expect(action[0].type).toBe("ADD_INPUTS")
  • expect(action[1].type).toBe("SUBTRACT_INPUTS")
  • });
  • ``
  • });

Clone this wiki locally