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

后端 未结 2 1448
北海茫月
北海茫月 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:31

    The easiest (and officially suggested) way is to do it like this:

        it('should navigate to the customers detail page', () => {
          actions$ = of({ type: '[Customers Page] Customer Selected', name: 'Bob' });
    
          // create a spy to verify the navigation will be called
          spyOn(router, 'navigateByUrl');
    
          // subscribe to execute the Effect
          effects.selectCustomer$.subscribe();
    
          // verify the navigation has been called
          expect(router.navigateByUrl).toHaveBeenCalledWith('customers/bob');
        });
    

    Here is the source.

提交回复
热议问题