为什么.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);
});
});
所有失败测试的摘要 FAIL客户端/容器/路由/ AuthorizedRoutes.test.js
AuthorizedRoutes组件>应包含主要组件
TypeError:expect(...)。find不是函数
答案 0 :(得分:0)
我错误地使用了.find
以下是如何使用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);
});
答案 1 :(得分:0)
如果要查找具有特定testID道具的组件,这是另外
dyld: Library not loaded: @rcpath/libGLEW.2.1.dylib
Referenced from:@rcpath/Xcode/DerivedData/GLFW_opengl-digmcjjsxnhrabepersfaxavutvh/Build/Products/Debug/GLFW opengl
Reason: no suitable image found.
Did find: /usr/local/opt/glew/lib/libGLEW.2.1.dylib:
code signature in (/usr/local/opt/glew/lib/libGLEW.2.1.dylib) not valid for use in process using Library Validation:
mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.