使用Apollo Angular客户端时,如何对缓存查询进行单元测试?

我的目标是对Angular中使用apollo客户端缓存功能readFragment的组件进行单元测试。

我遵循了Apollo的this guide,但没有看到使用客户端缓存的测试代码的任何示例。

我相关的代码将apollo注入到构造函数中,并执行以下readFragment:

import { Apollo } from 'apollo-angular';

constructor(private apollo: Apollo) {}

const role = cache.readFragment({
    fragment: EddyUserRoleBadgeFragmentDoc,id: `EddyUserRole:${roleId}`,});

在我的规范中,我希望使用ApolloTestingController

describe('cmpt name',() => {
 let controller: ApolloTestingController;

 beforeEach(() => {}) // Code that sets up cmpt,and sets the controller above

 afterEach(() => {
   controller.verify();
 });

 it('first test',() => {
   // How should I use the controller here - to mock the readFragment against the cache?
   const op = controller.
 });

});

非常欢迎任何帮助。

当前解决方法

我在configureTestingModule的提供者部分中将Apollo存入这样的被测组件中:

{
    provide: Apollo,useValue: {
        getclient: () => ({
            readFragment: () => ({ foo: 'bar' }),}),},
wz15116339558 回答:使用Apollo Angular客户端时,如何对缓存查询进行单元测试?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3040218.html

大家都在问