【发布时间】:2019-03-01 12:26:39
【问题描述】:
我正在尝试对效果进行简单的单元测试。我正在尝试实现此示例中的代码: https://github.com/ngrx/platform/blob/master/docs/effects/testing.md 但不幸的是,由于 authActions,我无法编译代码。这一行:
authActions = hot('--a-', { a: action });
给我编译错误,例如:
类型“TestHotObservable”缺少类型中的以下属性 'Subject':观察者、关闭、isStopped、hasError 等 5 个。
这里是代码 sn-p:
import { AuthEffects } from "./auth.effects";
import { Subject } from 'rxjs';
import { TestBed } from '@angular/core/testing';
import { provideMockActions } from '@ngrx/effects/testing';
import * as AuthActions from './auth.actions';
import { hot, cold } from 'jasmine-marbles';
import { RouterTestingModule } from '@angular/router/testing';
describe('AuthEffects', () => {
let authEffects: AuthEffects;
let authActions: Subject<any>;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule
],
providers: [
AuthEffects,
provideMockActions(() => authActions)
]
});
authEffects = TestBed.get(AuthEffects);
});
it('effect test', () => {
let username = '';
let password = '';
let role = 'PARENT';
const action = new AuthActions.TrySignin({ username, password, role });
const completion = new AuthActions.SigninUser()
authActions = hot('--a-', { a: action });
const expected = cold('--b', { b: completion });
expect(authEffects.authSignin).toBeObservable(expected);
})
})
由于我是新手,所以我没有想法。这里可能有什么问题?
【问题讨论】:
标签: angular unit-testing karma-jasmine ngrx