How to unit test this effect (with {dispatch: false})?

后端 未结 2 1445
北海茫月
北海茫月 2021-02-13 00:37

ngrx and unit testing beginner here. I have the following effect:

@Injectable()
export class NotificationEffects {
  @Effe         


        
2条回答
  •  悲&欢浪女
    2021-02-13 01:38

    So it's as simple as this:

    describe('notificationShow$', () => {
      let effects: NotificationEffects;
      let service: any;
      let actions$: Observable;
      const payload = {test: 123};
    
      beforeEach( () => {
        TestBed.configureTestingModule( {
          providers: [
            NotificationEffects,
            provideMockActions( () => actions$ ),
            {
              provide: NotificationService,
              useValue: jasmine.createSpyObj('NotificationService', ['info'])
            }
          ]
        } );
    
        effects = TestBed.get(NotificationEffects);
        service = TestBed.get(NotificationService);
      });
    
      it('should call a notification service method info with a payload', () => {
        actions$ = cold('a', { a: new notificationAction.NotificationShowAction(payload) });
        effects.notificationShow$.subscribe(() => {
          expect(service.info).toHaveBeenCalledWith(payload);
        });
      });
    });
    

提交回复
热议问题