Created
May 17, 2020 19:33
-
-
Save splincode/ca0ef70e0c9aace4e73f38049359904d to your computer and use it in GitHub Desktop.
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
import { TestBed } from '@angular/core/testing'; | |
export interface ZooStateModel { | |
feedAnimals: string[]; | |
} | |
@StateRepository() | |
@State<ZooStateModel>({ | |
name: 'zoo', | |
defaults: { | |
feedAnimals: [] | |
} | |
}) | |
@Injectable() | |
export class ZooState extends NgxsDataRepository<ZooStateModel> { | |
@DataAction() | |
public feedAnimals(@Payload('animalsToFeed') animalsToFeed: string[]): void { | |
this.ctx.setState((state) => ({ feedAnimals: [...state.feedAnimals, ...animalsToFeed] })); | |
} | |
} | |
describe('Zoo', () => { | |
it('it toggles feed', ngxsTestingPlatform([ ZooState ], (store, zooState) => { | |
zooState.feedAnimals([ 'leaves', 'bark' ]); | |
expect(zooState.snapshot).toBe([ 'leaves', 'bark' ]); | |
})); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment