尝试使用安装酶查找子组件时抛出错误

时间:2019-02-25 07:08:14

标签: jestjs enzyme react-test-renderer

我在JCpenney1组件中有几个子组件,现在我尝试使用mount Enzyme测试找到一个子组件,这是我的代码:

    import React from 'react';
    import {shallow, configure, mount, render} from 'enzyme';
    import Adapter from 'enzyme-adapter-react-16';
    import renderer from 'react-test-renderer';
    import jcpenney1 from '../../containers/jcpenney/jcpenney1';
    import FormComponent from '../../components/FormComponent/FormComponent';
    import FormBodyComponent from '../../components/FormBodyComponent/FormBodyComponent';

    import uuidv1 from 'uuid';
    configure({ adapter: new Adapter() });
    describe('JC penney1 container testing', () =>{
    let wrapper;
        const propIds ={
            formId: uuidv1(),
            word:"JCPenney Header",
            dynamicWordId: uuidv1()
        }
    it('should render whole Form body component', () => {
            var mockedChildren = [];        
            var wrapper = mount(
                <jcpenney1
                    children={mockedChildren}
                />);
            expect(wrapper.find(FormBodyComponent).length).toBe(1);
        });

 })

但是在尝试运行此测试时,出现以下错误: JC penney1容器测试›应该渲染整个Form主体组件

expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  55 |                 children={mockedChildren}
  56 |             />);
> 57 |         expect(wrapper.find(FormBodyComponent).length).toBe(1);
     |                                                        ^
  58 |     });
  59 | });

  at Object.toBe (src/components/tests/jcpenney1.test.js:57:56)

谁能告诉我我在哪里做错了。

0 个答案:

没有答案