Skip to content

Instantly share code, notes, and snippets.

@splincode
Created May 17, 2020 19:33
Show Gist options
  • Save splincode/ca0ef70e0c9aace4e73f38049359904d to your computer and use it in GitHub Desktop.
Save splincode/ca0ef70e0c9aace4e73f38049359904d to your computer and use it in GitHub Desktop.
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