Skip to content
This repository has been archived by the owner on Dec 26, 2017. It is now read-only.

Latest commit

 

History

History
44 lines (38 loc) · 988 Bytes

testing.md

File metadata and controls

44 lines (38 loc) · 988 Bytes

Testing Effects

  1. Import the EffectsTestingModule in your testing module:
import { EffectsTestingModule, EffectsRunner } from '@ngrx/effects/testing';

describe('My Effect', () => {
  beforeEach(() => TestBed.configureTestingModule({
    imports: [
      EffectsTestingModule
    ],
    providers: [
      AuthEffects
    ]
  }));
});
  1. Inject the EffectsTestRunner:
let runner: EffectsRunner;
let authEffects: AuthEffects;

beforeEach(inject([
    EffectsRunner, AuthEffects
  ],
  (_runner, _authEffects) => {
    runner = _runner;
    authEffects = _authEffects;
  }
));
  1. Queue up actions and then subscribe to the effect you want to test asserting on the result:
it('should return a LOGIN_SUCCESS action after logging in', () => {
  runner.queue({ type: 'LOGIN' });

  authEffects.login$.subscribe(result => {
    expect(result).toEqual({ type: 'LOGIN_SUCCESS' });
  });
});