|
1 | 1 | import { TestBed } from '@angular/core/testing'; |
2 | 2 | import { signalStore, withMethods, withState } from '@ngrx/signals'; |
3 | | -import { updateState } from '../update-state'; |
| 3 | +import { asAction, updateState } from '../update-state'; |
4 | 4 | import { withDevtools } from '../with-devtools'; |
5 | 5 | import { setupExtensions } from './helpers.spec'; |
6 | 6 |
|
@@ -45,4 +45,29 @@ describe('updateState', () => { |
45 | 45 | { shop: { name: 'i4' } }, |
46 | 46 | ); |
47 | 47 | }); |
| 48 | + |
| 49 | + it('should set and send an action object', () => { |
| 50 | + const { sendSpy } = setupExtensions(); |
| 51 | + |
| 52 | + const Store = signalStore( |
| 53 | + { providedIn: 'root' }, |
| 54 | + withDevtools('shop'), |
| 55 | + withState({ name: 'Car' }), |
| 56 | + withMethods((store) => ({ |
| 57 | + setName(name: string) { |
| 58 | + updateState(store, asAction({ type: 'Set Name', name }), { name }); |
| 59 | + }, |
| 60 | + })), |
| 61 | + ); |
| 62 | + const store = TestBed.inject(Store); |
| 63 | + TestBed.flushEffects(); |
| 64 | + |
| 65 | + store.setName('i4'); |
| 66 | + TestBed.flushEffects(); |
| 67 | + |
| 68 | + expect(sendSpy).toHaveBeenLastCalledWith( |
| 69 | + { type: 'Set Name', name: 'i4' }, |
| 70 | + { shop: { name: 'i4' } }, |
| 71 | + ); |
| 72 | + }); |
48 | 73 | }); |
0 commit comments