1
1
import * as ngCore from '@angular/core' ;
2
- import { TestBed } from '@angular/core/testing' ;
2
+ import { TestBed , fakeAsync , flush } from '@angular/core/testing' ;
3
3
import { Store , StoreModule , META_REDUCERS } from '..' ;
4
4
import { createActiveRuntimeChecks } from '../src/runtime_checks' ;
5
5
import { RuntimeChecks } from '../src/models' ;
@@ -113,32 +113,29 @@ describe('Runtime checks:', () => {
113
113
describe ( 'State Serialization:' , ( ) => {
114
114
const invalidAction = ( ) => ( { type : ErrorTypes . UnserializableState } ) ;
115
115
116
- it ( 'should throw when enabled' , ( done : DoneFn ) => {
117
- const store = setupStore ( { strictStateSerializability : true } ) ;
118
-
119
- store . subscribe ( {
120
- error : err => {
121
- expect ( err ) . toMatch ( / D e t e c t e d u n s e r i a l i z a b l e s t a t e / ) ;
122
- done ( ) ;
123
- } ,
124
- } ) ;
125
-
126
- store . dispatch ( invalidAction ( ) ) ;
127
- } ) ;
128
-
129
- it ( 'should not throw when disabled' , ( done : DoneFn ) => {
130
- const store = setupStore ( { strictStateSerializability : false } ) ;
131
-
132
- store . subscribe ( {
133
- next : ( { state } ) => {
134
- if ( state . invalidSerializationState ) {
135
- done ( ) ;
136
- }
137
- } ,
138
- } ) ;
139
-
140
- store . dispatch ( invalidAction ( ) ) ;
141
- } ) ;
116
+ it (
117
+ 'should throw when enabled' ,
118
+ fakeAsync ( ( ) => {
119
+ const store = setupStore ( { strictStateSerializability : true } ) ;
120
+
121
+ expect ( ( ) => {
122
+ store . dispatch ( invalidAction ( ) ) ;
123
+ flush ( ) ;
124
+ } ) . toThrowError ( / D e t e c t e d u n s e r i a l i z a b l e s t a t e / ) ;
125
+ } )
126
+ ) ;
127
+
128
+ it (
129
+ 'should not throw when disabled' ,
130
+ fakeAsync ( ( ) => {
131
+ const store = setupStore ( { strictStateSerializability : false } ) ;
132
+
133
+ expect ( ( ) => {
134
+ store . dispatch ( invalidAction ( ) ) ;
135
+ flush ( ) ;
136
+ } ) . not . toThrow ( ) ;
137
+ } )
138
+ ) ;
142
139
} ) ;
143
140
144
141
describe ( 'Action Serialization:' , ( ) => {
@@ -147,63 +144,59 @@ describe('Runtime checks:', () => {
147
144
invalid : new Date ( ) ,
148
145
} ) ;
149
146
150
- it ( 'should throw when enabled' , ( done : DoneFn ) => {
151
- const store = setupStore ( { strictActionSerializability : true } ) ;
152
-
153
- store . subscribe ( {
154
- error : err => {
155
- expect ( err ) . toMatch ( / D e t e c t e d u n s e r i a l i z a b l e a c t i o n / ) ;
156
- done ( ) ;
157
- } ,
158
- } ) ;
159
- store . dispatch ( invalidAction ( ) ) ;
160
- } ) ;
161
-
162
- it ( 'should not throw when disabled' , ( done : DoneFn ) => {
163
- const store = setupStore ( { strictActionSerializability : false } ) ;
164
-
165
- store . subscribe ( {
166
- next : ( { state } ) => {
167
- if ( state . invalidSerializationAction ) {
168
- done ( ) ;
169
- }
170
- } ,
171
- } ) ;
172
-
173
- store . dispatch ( invalidAction ( ) ) ;
174
- } ) ;
147
+ it (
148
+ 'should throw when enabled' ,
149
+ fakeAsync ( ( ) => {
150
+ const store = setupStore ( { strictActionSerializability : true } ) ;
151
+
152
+ expect ( ( ) => {
153
+ store . dispatch ( invalidAction ( ) ) ;
154
+ flush ( ) ;
155
+ } ) . toThrowError ( / D e t e c t e d u n s e r i a l i z a b l e a c t i o n / ) ;
156
+ } )
157
+ ) ;
158
+
159
+ it (
160
+ 'should not throw when disabled' ,
161
+ fakeAsync ( ( ) => {
162
+ const store = setupStore ( { strictActionSerializability : false } ) ;
163
+
164
+ expect ( ( ) => {
165
+ store . dispatch ( invalidAction ( ) ) ;
166
+ flush ( ) ;
167
+ } ) . not . toThrow ( ) ;
168
+ } )
169
+ ) ;
175
170
} ) ;
176
171
177
172
describe ( 'State Mutations' , ( ) => {
178
173
const invalidAction = ( ) => ( {
179
174
type : ErrorTypes . MutateState ,
180
175
} ) ;
181
176
182
- it ( 'should throw when enabled' , ( done : DoneFn ) => {
183
- const store = setupStore ( { strictImmutability : true } ) ;
184
-
185
- store . subscribe ( {
186
- error : _ => {
187
- done ( ) ;
188
- } ,
189
- } ) ;
190
-
191
- store . dispatch ( invalidAction ( ) ) ;
192
- } ) ;
193
-
194
- it ( 'should not throw when disabled' , ( done : DoneFn ) => {
195
- const store = setupStore ( { strictImmutability : false } ) ;
196
-
197
- store . subscribe ( {
198
- next : ( { state } ) => {
199
- if ( state . invalidMutationState ) {
200
- done ( ) ;
201
- }
202
- } ,
203
- } ) ;
204
-
205
- store . dispatch ( invalidAction ( ) ) ;
206
- } ) ;
177
+ it (
178
+ 'should throw when enabled' ,
179
+ fakeAsync ( ( ) => {
180
+ const store = setupStore ( { strictImmutability : true } ) ;
181
+
182
+ expect ( ( ) => {
183
+ store . dispatch ( invalidAction ( ) ) ;
184
+ flush ( ) ;
185
+ } ) . toThrowError ( / C a n n o t a d d p r o p e r t y / ) ;
186
+ } )
187
+ ) ;
188
+
189
+ it (
190
+ 'should not throw when disabled' ,
191
+ fakeAsync ( ( ) => {
192
+ const store = setupStore ( { strictImmutability : false } ) ;
193
+
194
+ expect ( ( ) => {
195
+ store . dispatch ( invalidAction ( ) ) ;
196
+ flush ( ) ;
197
+ } ) . not . toThrow ( ) ;
198
+ } )
199
+ ) ;
207
200
} ) ;
208
201
209
202
describe ( 'Action Mutations' , ( ) => {
@@ -212,31 +205,29 @@ describe('Runtime checks:', () => {
212
205
foo : 'foo' ,
213
206
} ) ;
214
207
215
- it ( 'should throw when enabled' , ( done : DoneFn ) => {
216
- const store = setupStore ( { strictImmutability : true } ) ;
217
-
218
- store . subscribe ( {
219
- error : _ => {
220
- done ( ) ;
221
- } ,
222
- } ) ;
223
-
224
- store . dispatch ( invalidAction ( ) ) ;
225
- } ) ;
226
-
227
- it ( 'should not throw when disabled' , ( done : DoneFn ) => {
228
- const store = setupStore ( { strictImmutability : false } ) ;
229
-
230
- store . subscribe ( {
231
- next : ( { state } ) => {
232
- if ( state . invalidMutationAction ) {
233
- done ( ) ;
234
- }
235
- } ,
236
- } ) ;
237
-
238
- store . dispatch ( invalidAction ( ) ) ;
239
- } ) ;
208
+ it (
209
+ 'should throw when enabled' ,
210
+ fakeAsync ( ( ) => {
211
+ const store = setupStore ( { strictImmutability : true } ) ;
212
+
213
+ expect ( ( ) => {
214
+ store . dispatch ( invalidAction ( ) ) ;
215
+ flush ( ) ;
216
+ } ) . toThrowError ( / C a n n o t a s s i g n t o r e a d o n l y p r o p e r t y / ) ;
217
+ } )
218
+ ) ;
219
+
220
+ it (
221
+ 'should not throw when disabled' ,
222
+ fakeAsync ( ( ) => {
223
+ const store = setupStore ( { strictImmutability : false } ) ;
224
+
225
+ expect ( ( ) => {
226
+ store . dispatch ( invalidAction ( ) ) ;
227
+ flush ( ) ;
228
+ } ) . not . toThrow ( ) ;
229
+ } )
230
+ ) ;
240
231
} ) ;
241
232
} ) ;
242
233
0 commit comments