gpt4 book ai didi

angular - 类型 'TestHotObservable' 缺少类型 'Subject' 中的以下属性 : observers, closed、isStopped、hasError 以及另外 5 个

转载 作者:行者123 更新时间:2023-12-05 06:27:51 25 4
gpt4 key购买 nike

我正在尝试实现简单的单元测试效果。我正在尝试从这个例子中实现代码: https://github.com/ngrx/platform/blob/master/docs/effects/testing.md但不幸的是,由于 authActions,我无法编译代码。这一行:

authActions = hot('--a-', { a: action });

给我这样的编译错误:

Type 'TestHotObservable' is missing the following properties from type 'Subject': observers, closed, isStopped, hasError, and 5 more.

这是代码片段:

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);
})
})

由于我是新手,所以我没有想法。这里可能出了什么问题?

最佳答案

您必须将操作定义为 Observable - https://ngrx.io/guide/effects/testing

let actions: Observable<any>;

...

it('should work', () => {
actions = hot('--a-', { a: action });;
});

关于angular - 类型 'TestHotObservable' 缺少类型 'Subject<any>' 中的以下属性 : observers, closed、isStopped、hasError 以及另外 5 个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54944655/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com