reducers.test.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. import { reducerTester } from '../../../../test/core/redux/reducerTester';
  2. import { UsersState } from '../../../types';
  3. import { getMockUsers } from '../__mocks__/userMocks';
  4. import { initialState, setUsersSearchQuery, usersLoaded, usersReducer } from './reducers';
  5. describe('usersReducer', () => {
  6. describe('when usersLoaded is dispatched', () => {
  7. it('then state should be correct', () => {
  8. reducerTester<UsersState>()
  9. .givenReducer(usersReducer, { ...initialState })
  10. .whenActionIsDispatched(usersLoaded(getMockUsers(1)))
  11. .thenStateShouldEqual({
  12. ...initialState,
  13. users: getMockUsers(1),
  14. hasFetched: true,
  15. });
  16. });
  17. });
  18. describe('when setUsersSearchQuery is dispatched', () => {
  19. it('then state should be correct', () => {
  20. reducerTester<UsersState>()
  21. .givenReducer(usersReducer, { ...initialState })
  22. .whenActionIsDispatched(setUsersSearchQuery('a query'))
  23. .thenStateShouldEqual({
  24. ...initialState,
  25. searchQuery: 'a query',
  26. });
  27. });
  28. });
  29. });