首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >失败:对标准"Match DocumentNode“预期的一个匹配操作,没有找到

失败:对标准"Match DocumentNode“预期的一个匹配操作,没有找到
EN

Stack Overflow用户
提问于 2019-01-30 20:54:14
回答 1查看 2.5K关注 0票数 3

我试图写一个测试的角度服务,我正在使用的图形to &阿波罗。遵循本指南:阿波罗试验

我很感激你的帮助!

我收到了这个错误:失败:预期条件"Match DocumentNode“的匹配操作,找到none.

rules.spec.ts

代码语言:javascript
复制
import { PlatformGraphQLService } from 'platform-graphql'
import { TestBed, ComponentFixture } from '@angular/core/testing'
import { RulesService, GET_RULE_QUERY } from './rules.service'
import {
  ApolloTestingModule,
  ApolloTestingController
} from 'apollo-angular/testing'
import { async } from '@angular/core/testing'
import { HttpClientTestingModule } from '@angular/common/http/testing'
import { RulesComponent } from './rules.component'
import { Apollo, ApolloModule } from 'apollo-angular'

describe('RulesService', () => {
  let controller: ApolloTestingController
  beforeEach(() => {
    TestBed.configureTestingModule({
      declarations: [
        RulesComponent
      ],
      imports: [
        ApolloTestingModule,
        HttpClientTestingModule,
      ],
      providers: [
        PlatformGraphQLService,
        ApolloModule,
        Apollo
      ],
    })
    controller = TestBed.get(ApolloTestingController)
  })

  it('should return a rule from server', async(() => {
    const service: RulesService = TestBed.get(RulesService)

    service.loadRules()
      .valueChanges.subscribe(() => {
        expect(op.operation.variables.consequent.isExluded).toEqual(true)
      })

    const op = controller.expectOne(GET_RULE_QUERY)
    console.log(op)
    op.flush({
      'conditions': [
        {
          'glItemType': 'DEPARTMENT',
          'operation': 'LEQ',
          'value': 1300,
        },
        {
          'glItemType': 'SUBDEPARTMENT',
          'operation': 'GEQ',
          'value': 4805,
        }
      ],
      'consequent': {
        'isExluded': true,
      },
    })

  }))

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


})

EN

回答 1

Stack Overflow用户

发布于 2019-04-02 21:57:21

不确定您是否还在遇到这个问题,但我可以使用以下评论来解决这个问题:https://github.com/apollographql/apollo-angular/issues/691#issuecomment-417293424

它归结为三块:

  1. 向测试模块添加额外的提供程序
代码语言:javascript
复制
TestBed.configureTestingModule({
  ...
  providers: [
    ...
    {
      provide: APOLLO_TESTING_CACHE,
      useValue: new InMemoryCache({addTypename: true}),
    },
  ] 
});
  1. 将查询包装在expectOne中,调用addTypenameToDocument
代码语言:javascript
复制
const op = controller.expectOne(addTypenameToDocument(getClientsQuery));
  1. 将适当的__typename添加到模拟数据中.我相信在您的示例中,它将如下所示:
代码语言:javascript
复制
op.flush({
  'conditions': [
    {
      'glItemType': 'DEPARTMENT',
      'operation': 'LEQ',
      'value': 1300,
      '__typename': 'DefinedOnBackend'
    },
    {
      'glItemType': 'SUBDEPARTMENT',
      'operation': 'GEQ',
      'value': 4805,
      '__typename': 'DefinedOnBackend'
    }
  ],
  'consequent': {
    'isExluded': true,
    '__typename': 'DefinedOnBackend'
  },
})

对我来说,它看起来如下(实质上是将__typename添加到每个返回的记录中):

代码语言:javascript
复制
op.flush({
  data: {
    getClients: clients.map(c => ({ ...c, __typename: 'ClientDTO' }))
  }
});
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54449365

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档