小编Vik*_*ini的帖子

反应阿波罗测试不起作用。查询数据总是未定义

我在测试中仅获取加载状态和未定义的数据。我不知道为什么我要遵循给定示例中的所有内容。请帮忙。

测试文件。当我等待这条线执行时await wait(() => getByTestId('edit-category'));。它将查询的响应数据提供为未定义。错误:TypeError: Cannot read property 'getCategory' of undefined 第 34 行editConatinerCategory.tsx=>category={data!.getCategory!}

import React from 'react';
import gql from 'graphql-tag';
import { cleanup, wait } from 'react-testing-library';
import { customRender } from '../../../test-utils/customRender';
import { EditCategoryContainer } from './Container';

afterEach(() => {
  cleanup();
  console.error;
});
console.error = jest.fn();

const getCategoryMock = {
  request: {
    query: gql`
      query getCategory($id: Int!) {
        getCategory(id: $id) {
          id
          name
          active
          position
        }
      }
    `,
    variables: { …
Run Code Online (Sandbox Code Playgroud)

reactjs react-apollo react-testing-library

1
推荐指数
1
解决办法
5075
查看次数