You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
describe('reducerName reducer', () => {
it('should return the default state as an empty string', () => {
const result = reducerName(undefined, {});
expect(result).toEqual('');
});
it('reducerName should return new state when the action type is SET_CITY_NAME', () => {
const mockAction = {
type: 'SET_REDUCER_NAME',
reducerName: 'Susan'
};
const results = reducerName('', mockAction);
expect(results).toEqual(mockAction.re);
});
});
Testing mapStateToProps:
import { componentName, mapStateToProps} from './ComponentName';
describe('componentName Redux', () => {
it('mapStateToProps give all the needed data from state', () => {
const mockState = {
state1,
state2,
state3
};
const expected = {
state1,
state2
};
const mappedProps = mapStateToProps(mockState);
expect(mappedProps).toEqual(expected);
});
});
Testing mapDispatchToProps:
import * as actions from '../../actions';
import { componentName, mapDispatchToProps} from './ComponentName';
describe('MainForm mapDispatchToProps', () => {
it('should call dispatch with setDestination action when setDestination is called', () => {
const mockDispatch = jest.fn();
const mockDestination = 'DEN';
const actionToDispatch = actions.setDestination('SET_DESTINATION',mockDestination);
const mappedProps = mapDispatchToProps(mockDispatch);
mappedProps.setDestination('SET_DESTINATION',mockDestination);
expect(mockDispatch).toHaveBeenCalledWith(actionToDispatch);
});
});