|  | 
| 1 | 1 | import { expect } from 'chai'; | 
| 2 |  | -import identity from 'lodash/identity'; | 
| 3 | 2 | import { handleAction, createAction, createActions, combineActions } from '../'; | 
| 4 | 3 | 
 | 
| 5 | 4 | describe('handleAction()', () => { | 
| @@ -96,6 +95,20 @@ describe('handleAction()', () => { | 
| 96 | 95 |             counter: 7 | 
| 97 | 96 |           }); | 
| 98 | 97 |       }); | 
|  | 98 | + | 
|  | 99 | +      it('should not throw and return state when action is non-FSA', () => { | 
|  | 100 | +        const reducer = handleAction(type, (state) => state, defaultState); | 
|  | 101 | +        const action = { | 
|  | 102 | +          foo: { | 
|  | 103 | +            bar: 'baz' | 
|  | 104 | +          } | 
|  | 105 | +        }; | 
|  | 106 | + | 
|  | 107 | +        expect(reducer(undefined, action)).not.to.throw; | 
|  | 108 | +        expect(reducer(undefined, action)).to.deep.equal({ | 
|  | 109 | +          counter: 0 | 
|  | 110 | +        }); | 
|  | 111 | +      }); | 
| 99 | 112 |     }); | 
| 100 | 113 |   }); | 
| 101 | 114 | 
 | 
| @@ -239,36 +252,4 @@ describe('handleAction()', () => { | 
| 239 | 252 |         .to.deep.equal({ number: 3 }); | 
| 240 | 253 |     }); | 
| 241 | 254 |   }); | 
| 242 |  | - | 
| 243 |  | -  describe('with invalid actions', () => { | 
| 244 |  | -    it('should throw a descriptive error when the action object is missing', () => { | 
| 245 |  | -      const reducer = handleAction(createAction('ACTION_1'), identity, {}); | 
| 246 |  | -      expect( | 
| 247 |  | -        () => reducer(undefined) | 
| 248 |  | -      ).to.throw( | 
| 249 |  | -        Error, | 
| 250 |  | -        'The FSA spec mandates an action object with a type. Try using the createAction(s) method.' | 
| 251 |  | -      ); | 
| 252 |  | -    }); | 
| 253 |  | - | 
| 254 |  | -    it('should throw a descriptive error when the action type is missing', () => { | 
| 255 |  | -      const reducer = handleAction(createAction('ACTION_1'), identity, {}); | 
| 256 |  | -      expect( | 
| 257 |  | -        () => reducer(undefined, {}) | 
| 258 |  | -      ).to.throw( | 
| 259 |  | -        Error, | 
| 260 |  | -        'The FSA spec mandates an action object with a type. Try using the createAction(s) method.' | 
| 261 |  | -      ); | 
| 262 |  | -    }); | 
| 263 |  | - | 
| 264 |  | -    it('should throw a descriptive error when the action type is not a string or symbol', () => { | 
| 265 |  | -      const reducer = handleAction(createAction('ACTION_1'), identity, {}); | 
| 266 |  | -      expect( | 
| 267 |  | -        () => reducer(undefined, { type: false }) | 
| 268 |  | -      ).to.throw( | 
| 269 |  | -        Error, | 
| 270 |  | -        'The FSA spec mandates an action object with a type. Try using the createAction(s) method.' | 
| 271 |  | -      ); | 
| 272 |  | -    }); | 
| 273 |  | -  }); | 
| 274 | 255 | }); | 
0 commit comments