|
1 | 1 | import * as ngCore from '@angular/core';
|
2 | 2 | import { TestBed, fakeAsync, flush } from '@angular/core/testing';
|
3 |
| -import { Store, StoreModule, META_REDUCERS } from '..'; |
| 3 | +import { Store, StoreModule, META_REDUCERS, USER_RUNTIME_CHECKS } from '..'; |
4 | 4 | import { createActiveRuntimeChecks } from '../src/runtime_checks';
|
5 | 5 | import { RuntimeChecks } from '../src/models';
|
| 6 | +import * as metaReducers from '../src/meta-reducers'; |
6 | 7 |
|
7 | 8 | describe('Runtime checks:', () => {
|
8 | 9 | describe('createActiveRuntimeChecks:', () => {
|
@@ -68,6 +69,77 @@ describe('Runtime checks:', () => {
|
68 | 69 | });
|
69 | 70 | });
|
70 | 71 |
|
| 72 | + describe('USER_RUNTIME_CHECKS Token', () => { |
| 73 | + it('should be possible to toggle runtime reducers via the Injection Token', () => { |
| 74 | + const serializationCheckMetaReducerSpy = spyOn( |
| 75 | + metaReducers, |
| 76 | + 'serializationCheckMetaReducer' |
| 77 | + ).and.callThrough(); |
| 78 | + |
| 79 | + TestBed.configureTestingModule({ |
| 80 | + imports: [StoreModule.forRoot({})], |
| 81 | + providers: [ |
| 82 | + { |
| 83 | + provide: USER_RUNTIME_CHECKS, |
| 84 | + useValue: { |
| 85 | + strictStateSerializability: true, |
| 86 | + }, |
| 87 | + }, |
| 88 | + ], |
| 89 | + }); |
| 90 | + |
| 91 | + const _store = TestBed.get<Store<any>>(Store); |
| 92 | + expect(serializationCheckMetaReducerSpy).toHaveBeenCalled(); |
| 93 | + }); |
| 94 | + |
| 95 | + it('should not create a meta reducer if not desired', () => { |
| 96 | + const serializationCheckMetaReducerSpy = spyOn( |
| 97 | + metaReducers, |
| 98 | + 'serializationCheckMetaReducer' |
| 99 | + ).and.callThrough(); |
| 100 | + |
| 101 | + TestBed.configureTestingModule({ |
| 102 | + imports: [StoreModule.forRoot({})], |
| 103 | + providers: [ |
| 104 | + { |
| 105 | + provide: USER_RUNTIME_CHECKS, |
| 106 | + useValue: { |
| 107 | + strictStateSerializability: false, |
| 108 | + }, |
| 109 | + }, |
| 110 | + ], |
| 111 | + }); |
| 112 | + |
| 113 | + const _store = TestBed.get<Store<any>>(Store); |
| 114 | + expect(serializationCheckMetaReducerSpy).not.toHaveBeenCalled(); |
| 115 | + }); |
| 116 | + |
| 117 | + it('should not create a meta reducer without config', () => { |
| 118 | + const serializationCheckMetaReducerSpy = spyOn( |
| 119 | + metaReducers, |
| 120 | + 'serializationCheckMetaReducer' |
| 121 | + ).and.callThrough(); |
| 122 | + const immutabilityCheckMetaReducerSpy = spyOn( |
| 123 | + metaReducers, |
| 124 | + 'immutabilityCheckMetaReducer' |
| 125 | + ).and.callThrough(); |
| 126 | + |
| 127 | + TestBed.configureTestingModule({ |
| 128 | + imports: [StoreModule.forRoot({})], |
| 129 | + providers: [ |
| 130 | + { |
| 131 | + provide: USER_RUNTIME_CHECKS, |
| 132 | + useValue: {}, |
| 133 | + }, |
| 134 | + ], |
| 135 | + }); |
| 136 | + |
| 137 | + const _store = TestBed.get<Store<any>>(Store); |
| 138 | + expect(serializationCheckMetaReducerSpy).not.toHaveBeenCalled(); |
| 139 | + expect(immutabilityCheckMetaReducerSpy).not.toHaveBeenCalled(); |
| 140 | + }); |
| 141 | + }); |
| 142 | + |
71 | 143 | describe('Registering custom meta-reducers:', () => {
|
72 | 144 | it('should invoke internal meta reducers before user defined meta reducers', () => {
|
73 | 145 | let logs: string[] = [];
|
|
0 commit comments