@@ -41,23 +41,17 @@ describe('Selectors', () => {
41
41
it ( 'should deliver the value of selectors to the projection function' , ( ) => {
42
42
const projectFn = jasmine . createSpy ( 'projectionFn' ) ;
43
43
44
- const selector = createSelector (
45
- incrementOne ,
46
- incrementTwo ,
47
- projectFn
48
- ) ( { } ) ;
44
+ const selector = createSelector ( incrementOne , incrementTwo , projectFn ) (
45
+ { }
46
+ ) ;
49
47
50
48
expect ( projectFn ) . toHaveBeenCalledWith ( countOne , countTwo ) ;
51
49
} ) ;
52
50
53
51
it ( 'should allow an override of the selector return' , ( ) => {
54
52
const projectFn = jasmine . createSpy ( 'projectionFn' ) . and . returnValue ( 2 ) ;
55
53
56
- const selector = createSelector (
57
- incrementOne ,
58
- incrementTwo ,
59
- projectFn
60
- ) ;
54
+ const selector = createSelector ( incrementOne , incrementTwo , projectFn ) ;
61
55
62
56
expect ( selector . projector ( ) ) . toBe ( 2 ) ;
63
57
@@ -70,11 +64,7 @@ describe('Selectors', () => {
70
64
71
65
it ( 'should be possible to test a projector fn independent from the selectors it is composed of' , ( ) => {
72
66
const projectFn = jasmine . createSpy ( 'projectionFn' ) ;
73
- const selector = createSelector (
74
- incrementOne ,
75
- incrementTwo ,
76
- projectFn
77
- ) ;
67
+ const selector = createSelector ( incrementOne , incrementTwo , projectFn ) ;
78
68
79
69
selector . projector ( '' , '' ) ;
80
70
@@ -92,10 +82,7 @@ describe('Selectors', () => {
92
82
return state . unchanged ;
93
83
} ) ;
94
84
const projectFn = jasmine . createSpy ( 'projectionFn' ) ;
95
- const selector = createSelector (
96
- neverChangingSelector ,
97
- projectFn
98
- ) ;
85
+ const selector = createSelector ( neverChangingSelector , projectFn ) ;
99
86
100
87
selector ( firstState ) ;
101
88
selector ( secondState ) ;
@@ -126,13 +113,33 @@ describe('Selectors', () => {
126
113
expect ( projectFn ) . toHaveBeenCalledTimes ( 2 ) ;
127
114
} ) ;
128
115
116
+ it ( 'should not memoize last successful projection result in case of error' , ( ) => {
117
+ const firstState = { ok : true } ;
118
+ const secondState = { ok : false } ;
119
+ const fail = ( ) => {
120
+ throw new Error ( ) ;
121
+ } ;
122
+ const projectorFn = jasmine
123
+ . createSpy ( 'projectorFn' , ( s : any ) => ( s . ok ? s . ok : fail ( ) ) )
124
+ . and . callThrough ( ) ;
125
+ const selectorFn = jasmine
126
+ . createSpy ( 'selectorFn' , createSelector ( state => state , projectorFn ) )
127
+ . and . callThrough ( ) ;
128
+
129
+ selectorFn ( firstState ) ;
130
+
131
+ expect ( ( ) => selectorFn ( secondState ) ) . toThrow ( new Error ( ) ) ;
132
+ expect ( ( ) => selectorFn ( secondState ) ) . toThrow ( new Error ( ) ) ;
133
+
134
+ selectorFn ( firstState ) ;
135
+ expect ( selectorFn ) . toHaveBeenCalledTimes ( 4 ) ;
136
+ expect ( projectorFn ) . toHaveBeenCalledTimes ( 3 ) ;
137
+ } ) ;
138
+
129
139
it ( 'should allow you to release memoized arguments' , ( ) => {
130
140
const state = { first : 'state' } ;
131
141
const projectFn = jasmine . createSpy ( 'projectionFn' ) ;
132
- const selector = createSelector (
133
- incrementOne ,
134
- projectFn
135
- ) ;
142
+ const selector = createSelector ( incrementOne , projectFn ) ;
136
143
137
144
selector ( state ) ;
138
145
selector ( state ) ;
@@ -144,18 +151,9 @@ describe('Selectors', () => {
144
151
} ) ;
145
152
146
153
it ( 'should recursively release ancestor selectors' , ( ) => {
147
- const grandparent = createSelector (
148
- incrementOne ,
149
- a => a
150
- ) ;
151
- const parent = createSelector (
152
- grandparent ,
153
- a => a
154
- ) ;
155
- const child = createSelector (
156
- parent ,
157
- a => a
158
- ) ;
154
+ const grandparent = createSelector ( incrementOne , a => a ) ;
155
+ const parent = createSelector ( grandparent , a => a ) ;
156
+ const child = createSelector ( parent , a => a ) ;
159
157
spyOn ( grandparent , 'release' ) . and . callThrough ( ) ;
160
158
spyOn ( parent , 'release' ) . and . callThrough ( ) ;
161
159
@@ -271,20 +269,16 @@ describe('Selectors', () => {
271
269
describe ( 'createSelector with arrays' , ( ) => {
272
270
it ( 'should deliver the value of selectors to the projection function' , ( ) => {
273
271
const projectFn = jasmine . createSpy ( 'projectionFn' ) ;
274
- const selector = createSelector (
275
- [ incrementOne , incrementTwo ] ,
276
- projectFn
277
- ) ( { } ) ;
272
+ const selector = createSelector ( [ incrementOne , incrementTwo ] , projectFn ) (
273
+ { }
274
+ ) ;
278
275
279
276
expect ( projectFn ) . toHaveBeenCalledWith ( countOne , countTwo ) ;
280
277
} ) ;
281
278
282
279
it ( 'should be possible to test a projector fn independent from the selectors it is composed of' , ( ) => {
283
280
const projectFn = jasmine . createSpy ( 'projectionFn' ) ;
284
- const selector = createSelector (
285
- [ incrementOne , incrementTwo ] ,
286
- projectFn
287
- ) ;
281
+ const selector = createSelector ( [ incrementOne , incrementTwo ] , projectFn ) ;
288
282
289
283
selector . projector ( '' , '' ) ;
290
284
@@ -302,10 +296,7 @@ describe('Selectors', () => {
302
296
return state . unchanged ;
303
297
} ) ;
304
298
const projectFn = jasmine . createSpy ( 'projectionFn' ) ;
305
- const selector = createSelector (
306
- [ neverChangingSelector ] ,
307
- projectFn
308
- ) ;
299
+ const selector = createSelector ( [ neverChangingSelector ] , projectFn ) ;
309
300
310
301
selector ( firstState ) ;
311
302
selector ( secondState ) ;
@@ -337,10 +328,7 @@ describe('Selectors', () => {
337
328
it ( 'should allow you to release memoized arguments' , ( ) => {
338
329
const state = { first : 'state' } ;
339
330
const projectFn = jasmine . createSpy ( 'projectionFn' ) ;
340
- const selector = createSelector (
341
- [ incrementOne ] ,
342
- projectFn
343
- ) ;
331
+ const selector = createSelector ( [ incrementOne ] , projectFn ) ;
344
332
345
333
selector ( state ) ;
346
334
selector ( state ) ;
@@ -352,18 +340,9 @@ describe('Selectors', () => {
352
340
} ) ;
353
341
354
342
it ( 'should recursively release ancestor selectors' , ( ) => {
355
- const grandparent = createSelector (
356
- [ incrementOne ] ,
357
- a => a
358
- ) ;
359
- const parent = createSelector (
360
- [ grandparent ] ,
361
- a => a
362
- ) ;
363
- const child = createSelector (
364
- [ parent ] ,
365
- a => a
366
- ) ;
343
+ const grandparent = createSelector ( [ incrementOne ] , a => a ) ;
344
+ const parent = createSelector ( [ grandparent ] , a => a ) ;
345
+ const child = createSelector ( [ parent ] , a => a ) ;
367
346
spyOn ( grandparent , 'release' ) . and . callThrough ( ) ;
368
347
spyOn ( parent , 'release' ) . and . callThrough ( ) ;
369
348
0 commit comments