【问题标题】:React Apollo testing: MockProvider takes a long time when running testsReact Apollo 测试:运行测试时 MockProvider 需要很长时间
【发布时间】:2020-03-18 16:27:18
【问题描述】:

我在大约 20 个测试中使用来自 @apollo/react-testingMockedProvider,每个单独的测试运行大约 2.5 秒,但当一起运行时,其中一些随机需要 6-8 秒

我真的无法理解这一点,因为“慢”测试总是不同的,并且测试的执行顺序总是不同的。

每个测试都有以下结构

import React from 'react'
import { MemoryRouter } from 'react-router-dom'
import { MockedProvider } from '@apollo/react-testing'
import { render, cleanup} from '@testing-library/react'
import MyComponent from './'

describe('MyComponent', () => {
  afterEach(cleanup)
  it('queries for and displays MyComponent', async () => {
    const cmp = render(
      <MockedProvider mocks={mocks} addTypename={false}>
          <MyComponent />
      </MockedProvider>,
      { wrapper: MemoryRouter }
    )
    expect(cmp.getByText('something')).toBeInTheDocument()
  })
})

你有过类似的经历吗?知道我可以检查什么吗? 我上线了 react v16.9.0 @apollo/react-testing v3.1.3

【问题讨论】:

    标签: reactjs unit-testing react-apollo


    【解决方案1】:

    遇到了类似的问题。对我来说,问题是特定查询返回的记录太多。

    我有大约 4,000 个模拟结果作为数组返回,测试大约需要 4 到 5 秒才能完成。现在返回 10 个结果,它们减少到大约 75 毫秒。

    帮助我缩小范围的方法是使用 Chrome 的 Node.js 远程调试功能分析一项测试。 Kent C Dodds 做了一个简短的视频,对我有帮助:https://www.youtube.com/watch?v=RB2g-o39upo

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 2011-02-20
      • 2018-10-16
      • 2016-07-29
      • 1970-01-01
      • 2022-06-15
      相关资源
      最近更新 更多