【发布时间】:2019-01-18 03:51:08
【问题描述】:
我得到“不推荐使用源:这是内部实现细节,请勿使用。”当我在下面的代码上运行命令 npm lint 时:
set stream(source: Observable<any>) {
this.source = source;
}
如果我把它拿出来,它会满足 lint,但它会破坏我的单元测试。这是为什么呢?
【问题讨论】:
标签: javascript angular testing
我得到“不推荐使用源:这是内部实现细节,请勿使用。”当我在下面的代码上运行命令 npm lint 时:
set stream(source: Observable<any>) {
this.source = source;
}
如果我把它拿出来,它会满足 lint,但它会破坏我的单元测试。这是为什么呢?
【问题讨论】:
标签: javascript angular testing
如果您正在测试效果,则需要更新方法。我已经使用 provideMockActions 进行了更改,该操作将是一个 let actions$: Observable;
fdescribe('PizzaEffects', () => { let actions$: Observable;; 让服务:服务; 让效果:PizzaEffects; 常量数据 = givenPizzaData();
beforeEach(() => {
TestBed.configureTestingModule({
imports: [ApolloTestingModule],
providers: [
Service,
PizzaEffects,
Apollo,
// { provide: Actions, useFactory: getActions }, remove
provideMockActions(() => actions$),
]
});
actions$ = TestBed.get(Actions);
service = TestBed.get(Service);
effects = TestBed.get(PizzaEffects);
spyOn(service, 'loadData').and.returnValue(of(data));
});
describe('loadPizza', () => {
it('should return a collection from LoadPizzaSuccess', () => {
const action = new TriggerAction();
const completion = new LoadPizzaSuccess(data);
actions$ = hot('-a', { a: action });
const expected = cold('-b', { b: completion });
expect(effects.getPizzaEffect$).toBeObservable(expected);
});
});
});
【讨论】: