Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 在DOM上找不到使用expect test library和Ezyme具有两个类的元素_Reactjs_React Redux_Jestjs_Enzyme - Fatal编程技术网

Reactjs 在DOM上找不到使用expect test library和Ezyme具有两个类的元素

Reactjs 在DOM上找不到使用expect test library和Ezyme具有两个类的元素,reactjs,react-redux,jestjs,enzyme,Reactjs,React Redux,Jestjs,Enzyme,在测试React-Redux组件时,有没有办法通过第二个类名或具有两个或多个类名的元素来查找元素 例如,我有一个部门: .... 虽然我能找到它的第一类名称 const wrapper=mount( ); expect(wrapper.find('.navigations')).toHaveLength(4); 但无法通过第二个类名找到它。例如: expect(wrapper.find('.active')).toHaveLength(1) 它总是给我零的长度,但是活动类附加到DOM。 我

在测试React-Redux组件时,有没有办法通过第二个类名或具有两个或多个类名的元素来查找元素

例如,我有一个部门:


....
虽然我能找到它的第一类名称

const wrapper=mount(
);
expect(wrapper.find('.navigations')).toHaveLength(4);
但无法通过第二个类名找到它。例如:

expect(wrapper.find('.active')).toHaveLength(1)

它总是给我零的长度,但是活动类附加到DOM。
我只是想知道是否有任何方法可以访问它。

您应该可以同时执行这两项操作。。。我创建了快速测试来检查您的示例:

import React from 'react';
import { mount } from 'enzyme';

const MyComp = ({active}) => <div className={`navigations${active ? ' active': ''}`} />;

describe('Name of the group', () => {
  it('should ', () => {
    const wrapper = mount(
      <>
        <MyComp />
        <MyComp active/>
        <MyComp />
        <MyComp />
      </>,
    );

    expect(wrapper.find('.navigations')).toHaveLength(4);
    expect(wrapper.find('.active')).toHaveLength(1);
  });
});
从“React”导入React;
从“酶”导入{mount};
常量mycop=({active})=>;
描述('组名称',()=>{
它('应该',()=>{
常量包装器=装入(
,
);
expect(wrapper.find('.navigations')).toHaveLength(4);
expect(wrapper.find('.active')).toHaveLength(1);
});
});

使用Redux实现。使用codebin等沙箱共享您的代码。告诉我您的github用户名会更容易,这样我就可以访问您我的github是
MaciejTrojniarz