9
9
select ,
10
10
ReducerManagerDispatcher ,
11
11
UPDATE ,
12
- REDUCER_FACTORY ,
13
12
ActionReducer ,
14
13
Action ,
15
14
} from '../' ;
@@ -23,10 +22,7 @@ import {
23
22
counterReducer2 ,
24
23
} from './fixtures/counter' ;
25
24
import Spy = jasmine . Spy ;
26
- import any = jasmine . any ;
27
- import { skip , take } from 'rxjs/operators' ;
28
- import { MockStore , provideMockStore } from '../testing' ;
29
- import { createSelector } from '../src/selector' ;
25
+ import { take } from 'rxjs/operators' ;
30
26
31
27
interface TestAppSchema {
32
28
counter1 : number ;
@@ -447,180 +443,6 @@ describe('ngRx Store', () => {
447
443
}
448
444
} ) ;
449
445
450
- describe ( 'Mock Store' , ( ) => {
451
- let mockStore : MockStore < TestAppSchema > ;
452
- const initialState = { counter1 : 0 , counter2 : 1 , counter4 : 3 } ;
453
- const stringSelector = 'counter4' ;
454
- const memoizedSelector = createSelector (
455
- ( ) => initialState ,
456
- state => state . counter4
457
- ) ;
458
-
459
- beforeEach ( ( ) => {
460
- TestBed . configureTestingModule ( {
461
- providers : [
462
- provideMockStore ( {
463
- initialState,
464
- selectors : [
465
- { selector : stringSelector , value : 87 } ,
466
- { selector : memoizedSelector , value : 98 } ,
467
- ] ,
468
- } ) ,
469
- ] ,
470
- } ) ;
471
-
472
- mockStore = TestBed . get ( Store ) ;
473
- } ) ;
474
-
475
- it ( 'should set the initial state to a mocked one' , ( done : DoneFn ) => {
476
- const fixedState = {
477
- counter1 : 17 ,
478
- counter2 : 11 ,
479
- counter3 : 25 ,
480
- } ;
481
- mockStore . setState ( fixedState ) ;
482
- mockStore . pipe ( take ( 1 ) ) . subscribe ( {
483
- next ( val ) {
484
- expect ( val ) . toEqual ( fixedState ) ;
485
- } ,
486
- error : done . fail ,
487
- complete : done ,
488
- } ) ;
489
- } ) ;
490
-
491
- it ( 'should allow tracing dispatched actions' , ( ) => {
492
- const action = { type : INCREMENT } ;
493
- mockStore . scannedActions$
494
- . pipe ( skip ( 1 ) )
495
- . subscribe ( scannedAction => expect ( scannedAction ) . toEqual ( action ) ) ;
496
- mockStore . dispatch ( action ) ;
497
- } ) ;
498
-
499
- it ( 'should allow mocking of store.select with string selector using provideMockStore' , ( ) => {
500
- const expectedValue = 87 ;
501
-
502
- mockStore
503
- . select ( stringSelector )
504
- . subscribe ( result => expect ( result ) . toBe ( expectedValue ) ) ;
505
- } ) ;
506
-
507
- it ( 'should allow mocking of store.select with a memoized selector using provideMockStore' , ( ) => {
508
- const expectedValue = 98 ;
509
-
510
- mockStore
511
- . select ( memoizedSelector )
512
- . subscribe ( result => expect ( result ) . toBe ( expectedValue ) ) ;
513
- } ) ;
514
-
515
- it ( 'should allow mocking of store.pipe(select()) with a memoized selector using provideMockStore' , ( ) => {
516
- const expectedValue = 98 ;
517
-
518
- mockStore
519
- . pipe ( select ( memoizedSelector ) )
520
- . subscribe ( result => expect ( result ) . toBe ( expectedValue ) ) ;
521
- } ) ;
522
-
523
- it ( 'should allow mocking of store.select with string selector using overrideSelector' , ( ) => {
524
- const mockValue = 5 ;
525
-
526
- mockStore . overrideSelector ( 'counter1' , mockValue ) ;
527
-
528
- mockStore
529
- . select ( 'counter1' )
530
- . subscribe ( result => expect ( result ) . toBe ( mockValue ) ) ;
531
- } ) ;
532
-
533
- it ( 'should allow mocking of store.select with a memoized selector using overrideSelector' , ( ) => {
534
- const mockValue = 5 ;
535
- const selector = createSelector (
536
- ( ) => initialState ,
537
- state => state . counter1
538
- ) ;
539
-
540
- mockStore . overrideSelector ( selector , mockValue ) ;
541
-
542
- mockStore
543
- . select ( selector )
544
- . subscribe ( result => expect ( result ) . toBe ( mockValue ) ) ;
545
- } ) ;
546
-
547
- it ( 'should allow mocking of store.pipe(select()) with a memoized selector using overrideSelector' , ( ) => {
548
- const mockValue = 5 ;
549
- const selector = createSelector (
550
- ( ) => initialState ,
551
- state => state . counter2
552
- ) ;
553
-
554
- mockStore . overrideSelector ( selector , mockValue ) ;
555
-
556
- mockStore
557
- . pipe ( select ( selector ) )
558
- . subscribe ( result => expect ( result ) . toBe ( mockValue ) ) ;
559
- } ) ;
560
-
561
- it ( 'should pass through unmocked selectors' , ( ) => {
562
- const mockValue = 5 ;
563
- const selector = createSelector (
564
- ( ) => initialState ,
565
- state => state . counter1
566
- ) ;
567
- const selector2 = createSelector (
568
- ( ) => initialState ,
569
- state => state . counter2
570
- ) ;
571
- const selector3 = createSelector (
572
- selector ,
573
- selector2 ,
574
- ( sel1 , sel2 ) => sel1 + sel2
575
- ) ;
576
-
577
- mockStore . overrideSelector ( selector , mockValue ) ;
578
-
579
- mockStore
580
- . pipe ( select ( selector2 ) )
581
- . subscribe ( result => expect ( result ) . toBe ( 1 ) ) ;
582
- mockStore
583
- . pipe ( select ( selector3 ) )
584
- . subscribe ( result => expect ( result ) . toBe ( 6 ) ) ;
585
- } ) ;
586
-
587
- it ( 'should allow you reset mocked selectors' , ( ) => {
588
- const mockValue = 5 ;
589
- const selector = createSelector (
590
- ( ) => initialState ,
591
- state => state . counter1
592
- ) ;
593
- const selector2 = createSelector (
594
- ( ) => initialState ,
595
- state => state . counter2
596
- ) ;
597
- const selector3 = createSelector (
598
- selector ,
599
- selector2 ,
600
- ( sel1 , sel2 ) => sel1 + sel2
601
- ) ;
602
-
603
- mockStore
604
- . pipe ( select ( selector3 ) )
605
- . subscribe ( result => expect ( result ) . toBe ( 1 ) ) ;
606
-
607
- mockStore . overrideSelector ( selector , mockValue ) ;
608
- mockStore . overrideSelector ( selector2 , mockValue ) ;
609
- selector3 . release ( ) ;
610
-
611
- mockStore
612
- . pipe ( select ( selector3 ) )
613
- . subscribe ( result => expect ( result ) . toBe ( 10 ) ) ;
614
-
615
- mockStore . resetSelectors ( ) ;
616
- selector3 . release ( ) ;
617
-
618
- mockStore
619
- . pipe ( select ( selector3 ) )
620
- . subscribe ( result => expect ( result ) . toBe ( 1 ) ) ;
621
- } ) ;
622
- } ) ;
623
-
624
446
describe ( 'Meta Reducers' , ( ) => {
625
447
let metaReducerContainer : any ;
626
448
let metaReducerSpy1 : Spy ;
0 commit comments