|
1 | 1 | import { expect } from 'chai'; |
| 2 | +import identity from 'lodash/identity'; |
2 | 3 | import { handleAction, createAction, createActions, combineActions } from '../'; |
3 | 4 |
|
4 | 5 | describe('handleAction()', () => { |
@@ -195,4 +196,36 @@ describe('handleAction()', () => { |
195 | 196 | .to.deep.equal({ number: 3 }); |
196 | 197 | }); |
197 | 198 | }); |
| 199 | + |
| 200 | + describe('with invalid actions', () => { |
| 201 | + it('should throw a descriptive error when the action object is missing', () => { |
| 202 | + const reducer = handleAction(createAction('ACTION_1'), identity); |
| 203 | + expect( |
| 204 | + () => reducer(undefined) |
| 205 | + ).to.throw( |
| 206 | + Error, |
| 207 | + 'The FSA spec mandates an action object with a type. Try using the createAction(s) method.' |
| 208 | + ); |
| 209 | + }); |
| 210 | + |
| 211 | + it('should throw a descriptive error when the action type is missing', () => { |
| 212 | + const reducer = handleAction(createAction('ACTION_1'), identity); |
| 213 | + expect( |
| 214 | + () => reducer(undefined, {}) |
| 215 | + ).to.throw( |
| 216 | + Error, |
| 217 | + 'The FSA spec mandates an action object with a type. Try using the createAction(s) method.' |
| 218 | + ); |
| 219 | + }); |
| 220 | + |
| 221 | + it('should throw a descriptive error when the action type is not a string or symbol', () => { |
| 222 | + const reducer = handleAction(createAction('ACTION_1'), identity); |
| 223 | + expect( |
| 224 | + () => reducer(undefined, { type: false }) |
| 225 | + ).to.throw( |
| 226 | + Error, |
| 227 | + 'The FSA spec mandates an action object with a type. Try using the createAction(s) method.' |
| 228 | + ); |
| 229 | + }); |
| 230 | + }); |
198 | 231 | }); |
0 commit comments