我正在尝试实施简单的单元测试。我正在尝试从此示例实现代码: https://github.com/ngrx/platform/blob/master/docs/effects/testing.md 但不幸的是,由于authActions,我无法编译代码。这行:
authActions = hot('--a-', { a: action });
给我编译错误,例如:
类型'TestHotObservable'缺少以下类型的属性 “主题”:观察者,已关闭,isStopped,hasError和另外5个。
以下是代码段:
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);
})
})
由于我是新手,所以我没主意。这里可能出什么问题了?
答案 0 :(得分:0)
您必须将操作定义为可观察的-https://ngrx.io/guide/effects/testing
let actions: Observable<any>;
...
it('should work', () => {
actions = hot('--a-', { a: action });;
});