|
| 1 | +import React, { Component } from 'react' |
| 2 | +import { mapStateToProps, mapDispatchToProps } from './WithErrors' |
| 3 | +import { buildError, |
| 4 | + addError, |
| 5 | + removeError, |
| 6 | + clearErrors } from '../../../services/Error/Error' |
| 7 | + |
| 8 | +jest.mock('../../../services/Error/Error') |
| 9 | + |
| 10 | +let basicState = null |
| 11 | + |
| 12 | +beforeEach(() => { |
| 13 | + basicState = { |
| 14 | + currentErrors: "some error" |
| 15 | + } |
| 16 | +}) |
| 17 | + |
| 18 | +test("mapStateToProps maps currentErrors to errors", () => { |
| 19 | + const mappedProps = mapStateToProps(basicState) |
| 20 | + expect(mappedProps.errors).toEqual(basicState.currentErrors) |
| 21 | + |
| 22 | + expect(mappedProps).toMatchSnapshot() |
| 23 | +}) |
| 24 | + |
| 25 | +test("mapDispatchToProps maps function buildError", () => { |
| 26 | + const dispatch = jest.fn(() => Promise.resolve()) |
| 27 | + const mappedProps = mapDispatchToProps(dispatch, {}) |
| 28 | + |
| 29 | + expect(mappedProps.buildError).toBe(buildError) |
| 30 | +}) |
| 31 | + |
| 32 | +test("mapDispatchToProps maps function addError", () => { |
| 33 | + const dispatch = jest.fn(() => Promise.resolve()) |
| 34 | + const mappedProps = mapDispatchToProps(dispatch, {}) |
| 35 | + |
| 36 | + mappedProps.addError("thisError") |
| 37 | + expect(dispatch).toBeCalled() |
| 38 | + expect(addError).toBeCalledWith("thisError") |
| 39 | +}) |
| 40 | + |
| 41 | +test("mapDispatchToProps maps function addError", () => { |
| 42 | + const dispatch = jest.fn(() => Promise.resolve()) |
| 43 | + const mappedProps = mapDispatchToProps(dispatch, {}) |
| 44 | + |
| 45 | + mappedProps.addError("thisError") |
| 46 | + expect(dispatch).toBeCalled() |
| 47 | + expect(addError).toBeCalledWith("thisError") |
| 48 | +}) |
| 49 | + |
| 50 | +test("mapDispatchToProps maps function clearErrors", () => { |
| 51 | + const dispatch = jest.fn(() => Promise.resolve()) |
| 52 | + const mappedProps = mapDispatchToProps(dispatch, {}) |
| 53 | + |
| 54 | + mappedProps.clearErrors() |
| 55 | + expect(dispatch).toBeCalled() |
| 56 | + expect(clearErrors).toBeCalled() |
| 57 | +}) |
0 commit comments