首页 > 解决方案 > 酶找不到类

问题描述

那是<Foo />我要测试的组件

...

return (
            <span
                className={`foo ${a === 'b' ? 'bar' : ''} ${className}`}>

                {kitten === 'cats' ?

                    <Cat
                        ... />
                    :

                    <Dog
                       ... />
                }

                <div
                    className={
                        `find-me 
                    ${foo === 'bar' ? 'abc' : 'def'} 
                    ${cats}
                    ${dogs}`
                    }>

                    {
                        children.map((obj, index) => {
                            ...
                        }
               </div>
           </span>
...

这就是我尝试测试的方式

it('constructs correctly when there are three children rendered', () => {
    const component = mount(
        <Foo >
            {options}
        </Foo>
    );

    expect(component.find('.find-me').children()).to.have.lengthOf(3);

    component.unmount();
});

但我明白了

TypeError:无法读取未定义的属性“拥有”

为什么找不到类?

标签: reactjsjestjsenzyme

解决方案


推荐阅读