茉莉花单元测试错误“期望的对象({})等于未定义。”

时间:2019-01-24 01:45:18

标签: javascript angular mocking karma-jasmine

我正在进行茉莉花单元测试。而且我正在尝试不捕捉特定对象。

我有这种方法:

getDiplomaSnapshot(): StateInterface {
        return Object.assign({}, this.diplomasState);
    }

它的单元测试如下:

 it('It should return diplomaSnapshot', ()  => {
        diplomaStoreServiceMock.returnState(this.diplomaState);
        const diplomaState = diplomaService.getDiplomaSnapshot();
        expect(diplomaState).toEqual(this.diplomaState);
    });

但随后出现此错误:

Expected Object({  }) to equal undefined.

谢谢

这是StoreServiceMock:

export class StoreServiceMock<TState> extends ObservableServiceMock<TState> {

    constructor(cls: any, initialState?: TState) {
        super(false, initialState !== undefined ? initialState : new cls() as TState);
        this.observable.subscribe();
    }

    getState(): Observable<TState> {
        return this.observable;
    }

    returnState(state) {
        this.setResponse(state);
        this.returnSuccessResponse();
    }

0 个答案:

没有答案