Невозможно протестировать контейнер React с дочерними компонентами. - PullRequest
0 голосов
/ 22 мая 2018

У меня есть контейнер реакции, в который я загружаю компонент карты без состояния по умолчанию без каких-либо условий, но во время тестирования я не могу пройти тест.

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);
  });
});

Я ожидаю длину компонента карты, но яЯ получаю 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)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...