|
| 1 | +import * as ngCore from '@angular/core'; |
1 | 2 | import { on, createReducer, createAction, props, union } from '@ngrx/store';
|
2 | 3 | import { expecter } from 'ts-snippet';
|
3 | 4 |
|
@@ -86,6 +87,59 @@ import {on} from './modules/store/src/reducer_creator';
|
86 | 87 | state = fooBarReducer(state, bar({ bar: 54 }));
|
87 | 88 | expect(state).toEqual(['[foobar] FOO', '[foobar] BAR']);
|
88 | 89 | });
|
| 90 | + |
| 91 | + describe('warning message when the same action type gets registered', () => { |
| 92 | + it('should not warn when not violated', () => { |
| 93 | + const spy = spyOn(console, 'warn'); |
| 94 | + |
| 95 | + const fooBarReducer = createReducer( |
| 96 | + [], |
| 97 | + on(foo, state => state), |
| 98 | + on(bar, state => state) |
| 99 | + ); |
| 100 | + |
| 101 | + expect(spy).not.toHaveBeenCalled(); |
| 102 | + }); |
| 103 | + |
| 104 | + it('should warn in dev mode', () => { |
| 105 | + const spy = spyOn(console, 'warn'); |
| 106 | + |
| 107 | + const fooBarReducer = createReducer( |
| 108 | + [], |
| 109 | + on(foo, state => state), |
| 110 | + on(bar, state => state), |
| 111 | + on(foo, state => state) |
| 112 | + ); |
| 113 | + |
| 114 | + expect(spy).toHaveBeenCalledTimes(1); |
| 115 | + }); |
| 116 | + |
| 117 | + it('should warn in dev mode with multiple actions', () => { |
| 118 | + const spy = spyOn(console, 'warn'); |
| 119 | + |
| 120 | + const fooBarReducer = createReducer( |
| 121 | + [], |
| 122 | + on(foo, foo, state => state), |
| 123 | + on(bar, state => state) |
| 124 | + ); |
| 125 | + |
| 126 | + expect(spy).toHaveBeenCalledTimes(1); |
| 127 | + }); |
| 128 | + |
| 129 | + it('should not warn in prod mode', () => { |
| 130 | + spyOn(ngCore, 'isDevMode').and.returnValue(false); |
| 131 | + const spy = spyOn(console, 'warn'); |
| 132 | + |
| 133 | + const fooBarReducer = createReducer( |
| 134 | + [], |
| 135 | + on(foo, state => state), |
| 136 | + on(bar, state => state), |
| 137 | + on(foo, state => state) |
| 138 | + ); |
| 139 | + |
| 140 | + expect(spy).not.toHaveBeenCalled(); |
| 141 | + }); |
| 142 | + }); |
89 | 143 | });
|
90 | 144 | });
|
91 | 145 | });
|
0 commit comments