测试包装查询组件的问题

时间:2019-12-11 09:56:20

标签: reactjs graphql react-apollo apollo-client react-testing-library

我对React测试非常陌生,我正在尝试在我创建的Apollo Query之上为MyReload包装器组件编写Jest /酶单元测试。基本上,这会将refetchers添加到数组中(可以在以后的时间点执行)。

用法:

<MyReloadQuery id='1234 .....> // do something.. children </MyReloadQuery>

组件:

import React, { Component } from "react";
import PropTypes from "prop-types";
import { Subscribe } from "unstated";
import { Query } from "react-apollo";
import { MyReloadContainer } from "./MyReloadContainer";


export class MyReloadQuery extends Component {
  static propTypes = {
    children: PropTypes.any
  };

  componentWillUnmount() {
    this.onUnmount();
  }

  render() {
    return (
      <Subscribe to={[MyReloadContainer]}>
        {refetchers => (
          <Query {...this.props}>
            {(...args) => {
              const { refetch } = args[0];

              this.onUnmount = () => {
                refetchers.removeRefetcher(refetch);
              };

              refetchers.addRefetcher(refetch);

              return this.props.children(...args);
            }}
          </Query>
        )}
      </Subscribe>
    );
  }
}

我对React还是很陌生,它正在测试中,我想知道如何针对其中的一个虚拟数据进行测试?

有人可以启发我吗?任何帮助,将不胜感激:pray:

0 个答案:

没有答案