Unit Testing

Unit testing is easy with NGXS and NGXS Data plugin. A basic test looks like this:

describe('AppState', () => {
  @StateRepository()
  @State({
    name: 'app',
    defaults: 'hello world',
  })
  @Injectable()
  class AppState extends NgxsDataRepository<string> {}

  it(
    'should be correct ensure state from AppState',
    ngxsTestingPlatform([AppState], (store: Store, app: AppState) => {
      expect(store.snapshot()).toEqual({app: 'hello world'});
      expect(app.getState()).toEqual('hello world');
    }),
  );
});

ngxsTestingPlatform - This is a testing platform that allows you to fully test the entire lifecycle of NGXS methods.

Example where we testing NGXS Lifecycle

Last updated