如何使用 <TestContext> 在 React-Admin 中测试组件视图?

问题描述

我想知道如何使用 <TestContext> 作为测试 react-admin 自定义组件视图的足够工具。到目前为止,我们还没有遇到在 <TestContext> 中呈现基本 HTML 元素的错误,但是 RA 组件测试失败的主要原因是:

TypeError: Cannot create proxy with a non-object as target or handler

在我们的例子中,我们没有连接到我们的组件的 redux 存储,现在只想使用来自 documentation 的示例使用简单的 props 测试显示

describe('<EditManufacturer/>',() => {
  let testUtils: any;

  beforeEach(() => {
    const mockEditManufacturerProps = {
      basePath: '/',id: '123',resource: 'foo',};

    testUtils = render(
    <TestContext>
      <EditManufacturer {...mockEditManufacturerProps}/>
    </TestContext>)
  });


  // test

  })
});

上面的示例语法产生另一个错误

Cannot read property '{"type":"GET_ONE","resource":"foo","payload":{"id":"123"}}' of undefined

这是我们的 EditManufacturer.tsx 组件:

const EditManufacturer:React.FC<EditProps> = props => {
  return(
    <Edit {...props}>
      <SimpleForm>
        <ManufacturerInputFields/>
      </SimpleForm>
    </Edit>

  )};

export default EditManufacturer;

是为 HOC 注入所有必需的道具,然后按照答案 here 中提到的方式安装视图还是使用 e2e 测试是唯一的解决方案?任何帮助将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)