当我在下面的代码上运行命令npm lint
时,我会得到“源代码已过时:这是一个内部实现细节,请勿使用。”的提示:
set stream(source: Observable<any>) {
this.source = source;
}
如果我将其移除,它可以满足lint标准,但会导致我的单元测试失败。为什么会这样?
当我在下面的代码上运行命令npm lint
时,我会得到“源代码已过时:这是一个内部实现细节,请勿使用。”的提示:
set stream(source: Observable<any>) {
this.source = source;
}
如果您正在测试效果,则需要更新方法。我已更改使用provideMockActions,该操作将是let actions $:Observable;
fdescribe('PizzaEffects',()=&gt; { let actions $:Observable;; let service:Service; let effects:PizzaEffects; const data = 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);
});
});
});