我想在单元测试中使用模拟提供程序数据。 示例:
class MockSomeService {
date: 'dummy'
};
describe('Test something.component.ts:', () => {
beforeEach(nsTestBedBeforeEach([
SomethingComponent
], [{ provide: SomeService, useClass: MockSomeService }]));
afterEach(nsTestBedAfterEach(false));
it('test', (done) => {
nsTestBedRender(SomethingComponent)
.then((fixture: ComponentFixture<SomethingComponent>) => {
const component = fixture.componentRef.instance;
console.log(component.someService.date)
/* Getting actual SomeService not the mock one */
done();
});
});
});
我总是得到“实际”的SomeService,而不是模拟的。如何强制组件使用模拟提供程序数据?