@@ -455,7 +455,7 @@ describe('Selectors', () => {
455
455
} ) ;
456
456
457
457
describe ( 'createFeatureSelector' , ( ) => {
458
- let featureName = '@ngrx/router-store ' ;
458
+ let featureName = 'featureA ' ;
459
459
let featureSelector : ( state : any ) => number ;
460
460
let warnSpy : jasmine . Spy ;
461
461
@@ -481,50 +481,51 @@ describe('Selectors', () => {
481
481
) ;
482
482
483
483
expect ( featureState$ ) . toBeObservable ( expected$ ) ;
484
- expect ( warnSpy ) . not . toHaveBeenCalled ( ) ;
485
484
} ) ;
486
485
487
- it ( 'should warn if the feature does not exist in the state' , ( ) => {
488
- spyOn ( ngCore , 'isDevMode' ) . and . returnValue ( true ) ;
486
+ describe ( 'Warning' , ( ) => {
487
+ describe ( 'should not log when: ' , ( ) => {
488
+ it ( 'the feature does exist' , ( ) => {
489
+ spyOn ( ngCore , 'isDevMode' ) . and . returnValue ( true ) ;
490
+ const selector = createFeatureSelector ( 'featureA' ) ;
489
491
490
- const state = { otherState : '' } ;
492
+ selector ( { featureA : { } } ) ;
491
493
492
- const state$ = cold ( 'a' , { a : state } ) ;
493
- const expected$ = cold ( 'a' , { a : undefined } ) ;
494
+ expect ( warnSpy ) . not . toHaveBeenCalled ( ) ;
495
+ } ) ;
494
496
495
- const featureState$ = state$ . pipe (
496
- map ( featureSelector ) ,
497
- distinctUntilChanged ( )
498
- ) ;
497
+ it ( 'the feature key exist but is falsy' , ( ) => {
498
+ spyOn ( ngCore , 'isDevMode' ) . and . returnValue ( true ) ;
499
+ const selector = createFeatureSelector ( 'featureB' ) ;
499
500
500
- expect ( featureState$ ) . toBeObservable ( expected$ ) ;
501
- expect ( warnSpy ) . toHaveBeenCalledWith (
502
- 'The feature name "@ngrx/router-store" does not exist ' +
503
- 'in the state, therefore createFeatureSelector cannot ' +
504
- 'access it. Be sure it is imported in a loaded module using ' +
505
- "StoreModule.forRoot('@ngrx/router-store', ...) or " +
506
- "StoreModule.forFeature('@ngrx/router-store', ...). If the " +
507
- 'default state is intended to be undefined, as is the case ' +
508
- 'with router state, this development-only warning message can ' +
509
- 'be ignored.'
510
- ) ;
511
- } ) ;
501
+ selector ( { featureA : { } , featureB : undefined } ) ;
512
502
513
- it ( 'should not warn if not in development mode' , ( ) => {
514
- spyOn ( ngCore , 'isDevMode' ) . and . returnValue ( false ) ;
503
+ expect ( warnSpy ) . not . toHaveBeenCalled ( ) ;
504
+ } ) ;
515
505
516
- const state = { otherState : '' } ;
506
+ it ( 'not in development mode' , ( ) => {
507
+ spyOn ( ngCore , 'isDevMode' ) . and . returnValue ( false ) ;
508
+ const selector = createFeatureSelector ( 'featureB' ) ;
517
509
518
- const state$ = cold ( 'a' , { a : state } ) ;
519
- const expected$ = cold ( 'a' , { a : undefined } ) ;
510
+ selector ( { featureA : { } } ) ;
520
511
521
- const featureState$ = state$ . pipe (
522
- map ( featureSelector ) ,
523
- distinctUntilChanged ( )
524
- ) ;
512
+ expect ( warnSpy ) . not . toHaveBeenCalled ( ) ;
513
+ } ) ;
514
+ } ) ;
525
515
526
- expect ( featureState$ ) . toBeObservable ( expected$ ) ;
527
- expect ( warnSpy ) . not . toHaveBeenCalled ( ) ;
516
+ describe ( 'should log when: ' , ( ) => {
517
+ it ( 'feature key does not exist' , ( ) => {
518
+ spyOn ( ngCore , 'isDevMode' ) . and . returnValue ( true ) ;
519
+ const selector = createFeatureSelector ( 'featureB' ) ;
520
+
521
+ selector ( { featureA : { } } ) ;
522
+
523
+ expect ( warnSpy ) . toHaveBeenCalled ( ) ;
524
+ expect ( warnSpy . calls . mostRecent ( ) . args [ 0 ] ) . toMatch (
525
+ / T h e f e a t u r e n a m e " f e a t u r e B " d o e s n o t e x i s t /
526
+ ) ;
527
+ } ) ;
528
+ } ) ;
528
529
} ) ;
529
530
} ) ;
530
531
0 commit comments