-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(store): allow extending
State({...})
instead of decorating
- Loading branch information
Showing
5 changed files
with
103 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Component, Injectable } from '@angular/core'; | ||
import { bootstrapApplication } from '@angular/platform-browser'; | ||
import { Action, InitState, NgxsOnInit, provideStore, State, Store } from '@ngxs/store'; | ||
import { freshPlatform } from '@ngxs/store/internals/testing'; | ||
|
||
describe('State decorator returns a constructor function', () => { | ||
@Component({ selector: 'app-root', template: '', standalone: true }) | ||
class TestComponent {} | ||
|
||
it( | ||
'should call an InitState action handler before the ngxsOnInit method on root module initialisation', | ||
freshPlatform(async () => { | ||
// Arrange | ||
@Injectable() | ||
class FooState | ||
extends State<string[]>({ name: 'foo', defaults: [] }) | ||
implements NgxsOnInit | ||
{ | ||
ngxsOnInit() { | ||
this.setState([...this.getState(), 'onInit']); | ||
} | ||
|
||
@Action(InitState) | ||
initState() { | ||
this.setState([...this.getState(), 'initState']); | ||
} | ||
} | ||
|
||
// Act | ||
const { injector } = await bootstrapApplication(TestComponent, { | ||
providers: [provideStore([FooState])] | ||
}); | ||
|
||
const store = injector.get(Store); | ||
|
||
// Assert | ||
expect(store.snapshot().foo).toEqual(['initState', 'onInit']); | ||
}) | ||
); | ||
}); |