ngxs-labs / testing

More power for testing with @ngxs-labs/testing
MIT License
13 stars 3 forks source link

API 1.0 (in progress) #23

Open splincode opened 5 years ago

splincode commented 5 years ago

splincode commented 4 years ago

@aymeric-duchein How about new API for NGXS Testing?

import { NgxsTestingModule, MockedStore, MockedStateContext } from '@ngxs-labs/testing';
import { Store } from '@ngxs/store';

describe('Test', () => {
  let store: MockedStore;

   beforeAll(() => {
     TestBed. configureTestingModule({
          imports: [NgxsTestingModule.forRoot([ ZooState ])]
      });

      store = TestBed.get<MockedStore>(Store);
   });

   it('patchState have been called', () => {
     const ctx: MockedStateContext = store.getStateContextMocks('STATE_NAME');
     expect(ctx.patchState).toHaveBeenCalledWith({ animals: 2 });
   })
})
aymeric-duchein commented 4 years ago

This would be nice and help keep tests readable with less lines of codes. Besides all already implemented methods what do you think is missing? Before editing this issue you were talking about mocking state lifecycle, should we add this to this new MockedStore?

splincode commented 4 years ago

mocking state lifecycle Yes