Skip to content

Latest commit

 

History

History
50 lines (39 loc) · 1.3 KB

T8-ReducerTests.md

File metadata and controls

50 lines (39 loc) · 1.3 KB

Testing Lab 8: Reducer Tests

Objectives

  • Test a Reducer

Steps

Test a Reducer

  1. Create the file src\projects\state\__tests__\projectReducer-test.js

  2. Add the following code to test the updating of a project.

    src\projects\state\__tests__\projectReducer-test.js

    import { projectReducer, initialProjectState } from '../projectReducer';
    import { SAVE_PROJECT_SUCCESS } from '../projectTypes';
    import { Project } from '../../Project';
    import { MOCK_PROJECTS } from '../../MockProjects';
    describe('project reducer', () => {
      test('should update an existing project', () => {
        const project = MOCK_PROJECTS[0];
        const updatedProject = Object.assign(new Project(), project, {
          name: project.name + ' updated',
        });
        const currentState = { ...initialProjectState, projects: [project] };
        const updatedState = {
          ...initialProjectState,
          projects: [updatedProject],
        };
        expect(
          projectReducer(currentState, {
            type: SAVE_PROJECT_SUCCESS,
            payload: updatedProject,
          })
        ).toEqual(updatedState);
      });
    });
  3. Verify the test passes.

    PASS  src/projects/state/__tests__/projectReducer-test.js

✔ You have completed Lab 8