类型'TestHotObservable'缺少类型'主题的以下属性 ':观察者,关闭,isStopped,hasError,还有5个

问题描述 投票:1回答:1

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

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

给我编译错误如:

类型'TestHotObservable'缺少类型'Subject'的以下属性:observers,closed,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);
    })
})

因为我是新手,所以我没有想法。这可能有什么问题?

angular unit-testing karma-jasmine ngrx
1个回答
0
投票

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

let actions: Observable<any>;

...

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

© www.soinside.com 2019 - 2024. All rights reserved.