【问题标题】:jest testing apollo provider getting error : TypeError: this.client.watchQuery is not a function开玩笑测试阿波罗提供者得到错误:TypeError: this.client.watchQuery is not a function
【发布时间】:2018-10-22 16:14:15
【问题描述】:

我收到错误:Invariant Violation: could not find "client" in the context of Query or as passed props。将根组件包裹在

然后我在测试时使用 prop 客户端将组件包装在 apollo 提供程序中。


TypeError: this.client.watchQuery is not a function

  732 |
  733 |   it('should close the overlay when the close button is clicked', () => {
> 734 |     const mandateBatchWrapper = mount(
  735 |       <ApolloProvider client={clientForApollo}>
  736 |         <MandateBatch
  737 |           data={data}

【问题讨论】:

  • 你最终解决了这个问题吗?

标签: unit-testing react-apollo


【解决方案1】:

您的 ApolloClient 可能会被嘲笑。如果你在某处有一个文件__mocks__/apollo-client.js,即使不调用jest.mock('apollo-client'),ApolloClient 也会被嘲笑。 https://jestjs.io/docs/en/manual-mocks#mocking-node-modules.

【讨论】:

    猜你喜欢
    • 2018-03-19
    • 2020-10-27
    • 2016-10-09
    • 1970-01-01
    • 1970-01-01
    • 2021-12-29
    • 1970-01-01
    • 2015-10-11
    • 1970-01-01
    相关资源
    最近更新 更多