Javascript 无法使用子组件测试React容器

Javascript 无法使用子组件测试React容器,javascript,reactjs,unit-testing,jestjs,enzyme,Javascript,Reactjs,Unit Testing,Jestjs,Enzyme,我有一个react容器,默认情况下,我在其中加载无状态组件,没有任何条件,而测试时我无法通过测试 import React from 'react'; import { configure, shallow, mount } from 'enzyme'; import Adapter from 'enzyme-adapter-react-16'; import { AddProduct } from './AddProducts'; import card from '../../compone

我有一个react容器,默认情况下,我在其中加载无状态组件,没有任何条件,而测试时我无法通过测试

import React from 'react';
import { configure, shallow, mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import { AddProduct } from './AddProducts';
import card from '../../components/UI/card/card';
import { MemoryRouter } from 'react-router-dom';

configure({ adapter: new Adapter() });

describe('<AddProduct />', () => {
  let wrapper;

  beforeEach(() => {
    wrapper = shallow(
      <MemoryRouter>
        <AddProduct title="hi" />
      </MemoryRouter>,
    );
  });

  it('should render the card when its load', () => {
    expect(wrapper.find(card)).toHaveLength(1);
  });
});
从“React”导入React;
从“酶”导入{configure,shall,mount};
从'enzyme-Adapter-react-16'导入适配器;
从“/AddProducts”导入{AddProduct};
从“../../components/UI/card/card”导入卡片;
从'react router dom'导入{MemoryRouter};
配置({adapter:newadapter()});
描述(“”,()=>{
让包装纸;
在每个之前(()=>{
包装纸=浅(
,
);
});
它('加载时应呈现卡',()=>{
expect(wrapper.find(card)).toHaveLength(1);
});
});
我期望卡组件的长度,但我收到0

 the Errors are like this.

● <AddProduct /> › should render the card when its load

    expect(received).toHaveLength(length)

    Expected value to have length:
      1
    Received:
 {"length": 0, Symbol(enzyme.__root__): {"length": 1, Symbol(enzyme.__root__): [Circular], Symbol(enzyme.__unrendered__): <MemoryRouter><AddProduct title="hi" /></MemoryRouter>, Symbol(enzyme.__renderer__): {"batchedUpdates": [Function batchedUpdates], "getNode": [Function getNode], "render": [Function render], "simulateEvent": [Function simulateEvent], "unmount": [Function unmount]},
Symbol(enzyme.__node__): {"instance": null, "key": undefined, "nodeType": "class", "props": {"children": <AddProduct title="hi" />, "history": {"action": "POP", "block": [Function block], "canGo": [Function canGo], "createHref": [Function createPath], "entries": [{"hash": "", "key": "3ozzvy", "pathname": "/", "search": "", "state": undefined}], "go": [Function go], "goBack": [Function goBack], "goForward": [Function goForward], "index": 0, "length": 1, "listen": [Function listen], "location": {"hash": "", "key": "3ozzvy", "pathname": "/", "search": "", "state": undefined}, "push": [Function push], "replace": [Function replace]}}, "ref": null, "rendered": {"instance": null, "key": undefined, "nodeType": "class", "props": {"title": "hi"}, "ref": null, "rendered": null, "type":
[Function AddProduct]}, "type": [Function Router]}, Symbol(enzyme.__nodes__): [{"instance": null, "key": undefined, "nodeType": "class", "props": {"children": <AddProduct title="hi" />, "history": {"action": "POP", "block": [Function block], "canGo": [Function canGo], "createHref": [Function createPath], "entries": [{"hash": "", "key": "3ozzvy", "pathname": "/", "search": "", "state": undefined}], "go": [Function go], "goBack": [Function goBack], "goForward": [Function goForward], "index": 0, "length": 1, "listen": [Function listen], "location": {"hash": "", "key": "3ozzvy", "pathname": "/", "search": "", "state": undefined}, "push": [Function push], "replace": [Function replace]}}, "ref": null, "rendered": {"instance": null, "key": undefined, "nodeType": "class", "props": {"title": "hi"}, "ref": null, "rendered": null, "type": [Function AddProduct]}, "type": [Function Router]}], Symbol(enzyme.__options__): {"adapter": {"options": {"enableComponentDidUpdateOnSetState": true}}}}, Symbol(enzyme.__unrendered__): null, Symbol(enzyme.__renderer__): {"batchedUpdates": [Function batchedUpdates], "getNode": [Function getNode], "render": [Function render], "simulateEvent": [Function simulateEvent], "unmount": [Function unmount]}, Symbol(enzyme.__node__): undefined, Symbol(enzyme.__nodes__): Array [], Symbol(enzyme.__options__): {"adapter": {"options": {"enableComponentDidUpdateOnSetState": true}}}}
    received.length:
      0

      at Object.it (src/containers/Products/AddProducts.test.js:18:46)
          at new Promise (<anonymous>)
      at Promise.resolve.then.el (node_modules/p-map/index.js:46:16)
          at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)
错误如下所示。
●  › 应在加载卡时呈现该卡
expect(已接收)。toHaveLength(长度)
期望值具有以下长度:
1.
收到:
{“长度”:0,符号(酶.uuuu根):{“长度”:1,符号(酶.uuuu根):[Circular],符号(酶.uuuuu未渲染):符号(酶.uuuuu渲染器):{“BatchedUpdate:[Function BatchedUpdate],“getNode:[Function getNode],“render:[Function render],“simulateEvent:[Function simulateEvent],“unmount:[Function unmount],
符号(酶.uuu节点.uuuuu):{“实例”:null,“键”:未定义,“节点类型”:“类”,“道具”:{“子项”:“历史”:{“操作”:“弹出”,“块”:[函数块],“canGo”:[Function canGo],“createHref”:[Function createPath],“条目”:[{“哈希”:“键”:“3ozvy”,“路径名”:“/,“搜索”:“状态”:未定义的}],“go,“goBack”:[函数goBack],“goForward”:[函数goForward],“index”:0,“length”:1,“listen”:[函数listen],“location”:{“hash”:“key”:“3ozvy”,“pathname”:“/”,“search”:“state”:未定义的},“push”:[函数push],“replace”:[函数替换]},“ref”:null,“rendered”:{“instance”:null,“key”:未定义的,“nodeype”:”类“,”props“:{“title”:“hi”},“ref”:null,“rendered”:null,“type”:
[Function AddProduct]},“type”:[Function Router]},Symbol(酵素).\uuuuu节点\uuuuuuu):[{“实例”:null,“键”:未定义,“节点类型”:“类”,“道具”:“{”子项”:“历史”:“{”动作”:“POP”,“块”:[Function block],“canGo”:[Function canGo],“createHref”:[Function createPath],“条目”:[{“哈希”:“,“键”:“3OZVY”,“路径名”:“/“搜索”“:”,“state”:未定义的}],“go”:[Function go],“goBack”:[Function goBack],“goForward”:[Function goForward],“index”:0,“length”:1,“listen”:[Function listen],“location”:{“hash”:“key”:“3ozvy”,“pathname”:“/,“search”:“state”:未定义的},“push”:[Function push],“replace”:[Function replace]},“ref”:null,“rendered”:{“实例”:null,“键”:未定义,“节点类型”:“类”,“道具”:{“标题”:“hi”},“ref”:null,“呈现”:null,“类型”:[Function AddProduct]},“类型”:[Function Router]}],Symbol(酵素){“适配器”:{“选项”:{“选项”:{“enableComponentDidUpdateOnSetState”:true}}}},Symbol(酵素){BatchedUpdate:[Function BatchedUpdate],“getNode:[Function getNode],“render:[Function render],“simulateEvent:[Function simulateEvent],“unmount:[Function unmount]},Symbol(enzyme.\uuuuuuuu nodes):[Function getNode],“render:[Function simulateEvent],“unmount:[Function unmount],[Function unmount],[Function unmount],[Function.\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
收到。长度:
0
在Object.it(src/containers/Products/AddProducts.test.js:18:46)
在新的承诺()
在Promise.resolve.then.el(node_modules/p-map/index.js:46:16)
在
在进程中。_tick回调(内部/process/next_tick.js:188:7)

哪个组件正在使用
组件?卡是=>内部的无状态组件呈现,而AddProduct是容器。为什么没有
,您不休息一下