Commits

Alexandre Vryghem authored c1875cade3a
Add expect().nothing() to reducer tests without expectations, who only exist to check if an error is thrown
No tags

src/app/core/cache/object-cache.reducer.spec.ts

Modified
119 119 it('should perform the ADD action without affecting the previous state', () => {
120 120 const state = Object.create(null);
121 121 const objectToCache = { self: selfLink1, type: Item.type, _links: { self: { href: selfLink1 } } };
122 122 const timeCompleted = new Date().getTime();
123 123 const msToLive = 900000;
124 124 const requestUUID = requestUUID1;
125 125 const action = new AddToObjectCacheAction(objectToCache, timeCompleted, msToLive, requestUUID, altLink1);
126 126 deepFreeze(state);
127 127
128 128 objectCacheReducer(state, action);
129 +
130 + // no expect required, deepFreeze will ensure an exception is thrown if the state
131 + // is mutated, and any uncaught exception will cause the test to fail
132 + expect().nothing();
129 133 });
130 134
131 135 it('should remove the specified object from the cache in response to the REMOVE action', () => {
132 136 const action = new RemoveFromObjectCacheAction(selfLink1);
133 137 const newState = objectCacheReducer(testState, action);
134 138
135 139 expect(testState[selfLink1]).not.toBeUndefined();
136 140 expect(newState[selfLink1]).toBeUndefined();
137 141 });
138 142
142 146 const newState = objectCacheReducer(testState, action);
143 147
144 148 expect(testState[wrongKey]).toBeUndefined();
145 149 expect(newState).toEqual(testState);
146 150 });
147 151
148 152 it('should perform the REMOVE action without affecting the previous state', () => {
149 153 const action = new RemoveFromObjectCacheAction(selfLink1);
150 154 // testState has already been frozen above
151 155 objectCacheReducer(testState, action);
156 +
157 + // no expect required, deepFreeze will ensure an exception is thrown if the state
158 + // is mutated, and any uncaught exception will cause the test to fail
159 + expect().nothing();
152 160 });
153 161
154 162 it('should set the timestamp of all objects in the cache in response to a RESET_TIMESTAMPS action', () => {
155 163 const newTimestamp = new Date().getTime();
156 164 const action = new ResetObjectCacheTimestampsAction(newTimestamp);
157 165 const newState = objectCacheReducer(testState, action);
158 166 Object.keys(newState).forEach((key) => {
159 167 expect(newState[key].timeCompleted).toEqual(newTimestamp);
160 168 });
161 169 });
162 170
163 171 it('should perform the RESET_TIMESTAMPS action without affecting the previous state', () => {
164 172 const action = new ResetObjectCacheTimestampsAction(new Date().getTime());
165 173 // testState has already been frozen above
166 174 objectCacheReducer(testState, action);
175 +
176 + // no expect required, deepFreeze will ensure an exception is thrown if the state
177 + // is mutated, and any uncaught exception will cause the test to fail
178 + expect().nothing();
167 179 });
168 180
169 181 it('should perform the ADD_PATCH action without affecting the previous state', () => {
170 182 const action = new AddPatchObjectCacheAction(selfLink1, [{
171 183 op: 'replace',
172 184 path: '/name',
173 185 value: 'random string'
174 186 }]);
175 187 // testState has already been frozen above
176 188 objectCacheReducer(testState, action);
189 +
190 + // no expect required, deepFreeze will ensure an exception is thrown if the state
191 + // is mutated, and any uncaught exception will cause the test to fail
192 + expect().nothing();
177 193 });
178 194
179 195 it('should when the ADD_PATCH action dispatched', () => {
180 196 const patch = [{ op: 'add', path: '/name', value: newName } as Operation];
181 197 const action = new AddPatchObjectCacheAction(selfLink1, patch);
182 198 const newState = objectCacheReducer(testState, action);
183 199 expect(newState[selfLink1].patches.map((p) => p.operations)).toContain(patch);
184 200 });
185 201
186 202 it('should when the APPLY_PATCH action dispatched', () => {

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut