我有一个使用 Apollo Angular 客户端来获取一些数据的组件。我正在尝试为它编写测试以检查它如何响应不同类型的数据。
但是,似乎确实有一种方法可以在第一次之后更改响应数据(我假设是由于缓存)。有没有办法在测试时清除缓存或强制它不使用缓存?
我的代码看起来像这样
describe('TestComponent', () => {
let apollo: ApolloTestingController;
let component: UserDetailsComponent;
let fixture: ComponentFixture<UserDetailsComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
ApolloTestingModule,
],
declarations: [TestComponent],
})
.compileComponents();
apollo = TestBed.get(ApolloTestingController);
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
}));
it('should work with data type 1', () => {
apollo.expectOne('TestQuery').flush({
data: {
something: 'test 1',
},
});
});
it('should work with data type 2', () => {
// Fails to match here
apollo.expectOne('TestQuery').flush({
data: {
something: 'test 2',
},
});
});
});