我正在进行茉莉花单元测试。而且我正在尝试不捕捉特定对象。
我有这种方法:
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();
}