我收到“源已弃用:这是一个内部实现细节,请勿使用。”当我在下面的代码上运行命令 npm lint
时:
set stream(source: Observable<any>) {
this.source = source;
}
如果我将其取出,它会满足 lint,但会破坏我的单元测试。这是为什么?
最佳答案
如果您正在测试效果,则需要更新方法。我已经使用 provideMockActions 进行了更改,该操作将是一个 let actions$: Observable;
fdescribe('PizzaEffects', () => { 让行动$:可观察的;; 让服务:服务; 让效果: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);
});
});
});
关于javascript - npm lint 上可观察到的 "source is deprecated"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54247522/