File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 11// LICENSE : MIT
22"use strict" ;
3+ const assert = require ( "assert" ) ;
34import { Store } from "almin" ;
45export default class ReduceStore extends Store {
56 constructor ( ) {
@@ -18,6 +19,12 @@ export default class ReduceStore extends Store {
1819 * @param {ReduceState } newState
1920 */
2021 setState ( newState ) {
22+ if ( process . env . NODE_ENV === 'development' ) {
23+ assert ( newState instanceof this . state . constructor , `newState should be instanceof exist this.state.constructor.
24+ newState: ${ newState }
25+ this.state.constructor: ${ this . state . constructor }
26+ ` ) ;
27+ }
2128 if ( this . state . equals ( newState ) ) {
2229 return ;
2330 }
Original file line number Diff line number Diff line change @@ -32,4 +32,22 @@ describe("ReduceStore", () => {
3232 useCase . execute ( ) ;
3333 } ) ;
3434 } ) ;
35+ context ( "when wrong setState" , ( ) => {
36+ it ( "should throw assertionError" , ( ) => {
37+ class TestStore extends ReduceStore {
38+ constructor ( ) {
39+ super ( ) ;
40+ this . state = new AlwaysNewState ( ) ;
41+ }
42+ }
43+ const store = new TestStore ( ) ;
44+ try {
45+ const invalidStateShape = { } ;
46+ store . setState ( invalidStateShape ) ;
47+ throw new Error ( "SHOULD NOT THROWN ERROR" ) ;
48+ } catch ( error ) {
49+ assert ( error . name === "AssertionError" ) ;
50+ }
51+ } ) ;
52+ } ) ;
3553} ) ;
You can’t perform that action at this time.
0 commit comments