我正在尝试实现简单的单元测试的效果。我正在尝试实现这个示例中的代码:https://github.com/ngrx/platform/blob/master/docs/effects/testing.md,但不幸的是,由于authActions,我无法编译代码。这一行:
authActions = hot('--a-', { a: action });给了我编译错误,比如:
类型'TestHotObservable‘缺少’Subject‘类型中的下列属性:观察者、关闭的、isStopped、hasError等。
这里是代码片段:
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);
})
})既然我是新手,我就没有主意了。这里可能出了什么问题?
发布于 2019-03-01 18:52:48
您必须将操作定义为可观察的- https://ngrx.io/guide/effects/testing。
let actions: Observable<any>;
...
it('should work', () => {
actions = hot('--a-', { a: action });;
});https://stackoverflow.com/questions/54944655
复制相似问题