是否可以使用 ApolloTestingModule 重置缓存?
Is it possible to reset the cache using ApolloTestingModule?
我有一个组件使用 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',
},
});
});
});
我发现你可以这样做
const apolloClient = TestBed.get(Apollo).getClient();
await apolloClient.clearStore();
我有一个组件使用 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',
},
});
});
});
我发现你可以这样做
const apolloClient = TestBed.get(Apollo).getClient();
await apolloClient.clearStore();