Javascript 酶测试:类型错误:预期(…)。查找不是函数
为什么Javascript 酶测试:类型错误:预期(…)。查找不是函数,javascript,testing,enzyme,jestjs,Javascript,Testing,Enzyme,Jestjs,为什么.find不是下面代码上下文中的函数 import React from 'react'; import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import { AuthorizedRoutesJest } from './AuthorizedRoutes'; // Components import { Main } from '../../components'; const wrappe
.find
不是下面代码上下文中的函数
import React from 'react';
import { shallow } from 'enzyme';
import toJson from 'enzyme-to-json';
import { AuthorizedRoutesJest } from './AuthorizedRoutes';
// Components
import {
Main
} from '../../components';
const wrapper = shallow(<AuthorizedRoutesJest />);
describe('<AuthorizedRoutes /> component', () => {
it('should render', () => {
const tree = toJson(wrapper);
expect(tree).toMatchSnapshot();
expect(wrapper).toHaveLength(1);
});
it('should contain a Main component', () => {
expect(wrapper).find(Main).toHaveLength(1);
});
});
从“React”导入React;
从“酶”导入{shall};
从“酶到json”导入toJson;
从“/authorizedLootesJest”导入{authorizedLootesJest};
//组成部分
进口{
主要
}来自“../../components”;
常量包装器=浅();
描述(‘组件’,()=>{
它('应该呈现',()=>{
consttree=toJson(包装器);
expect(tree.toMatchSnapshot();
expect(包装器).toHaveLength(1);
});
它('应该包含一个主要组件',()=>{
expect(包装器).find(主).toHaveLength(1);
});
});
所有失败测试的总结
客户端/容器/路由/authorizedLotes.test.js失败
组件›应包含一个主要组件
TypeError:expect(…)。find不是函数
我使用的
。查找不正确
以下是如何使用“查找”的示例:
it('should contain a ConnectedRouter component', () => {
expect(wrapper.find(ConnectedRouter)).toHaveLength(1);
});
it('should contain a Switch component', () => {
expect(wrapper.find(Switch)).toHaveLength(1);
});
it('should contain 7 Route components', () => {
expect(wrapper.find(Route)).toHaveLength(7);
});
我使用的。查找不正确
以下是如何使用“查找”的示例:
it('should contain a ConnectedRouter component', () => {
expect(wrapper.find(ConnectedRouter)).toHaveLength(1);
});
it('should contain a Switch component', () => {
expect(wrapper.find(Switch)).toHaveLength(1);
});
it('should contain 7 Route components', () => {
expect(wrapper.find(Route)).toHaveLength(7);
});
如果您想找到具有特定testID道具的组件,这是另外一个选项
it('should render the date when the message was sent', () => {
expect(chatBubbleComponent.findWhere((node) => node.prop('testID') === 'chat_sent_at')).toHaveLength(1);
});
如果您想找到具有特定testID道具的组件,这是另外一个选项
it('should render the date when the message was sent', () => {
expect(chatBubbleComponent.findWhere((node) => node.prop('testID') === 'chat_sent_at')).toHaveLength(1);
});