admin管理员组文章数量:1336320
Why is .find
not a function in the code context below?
import React from 'react';
import { shallow } from 'enzyme';
import toJson from 'enzyme-to-json';
import { AuthorizedRoutesJest } from './AuthorizedRoutes';
// Components
import {
Main
} from '../../ponents';
const wrapper = shallow(<AuthorizedRoutesJest />);
describe('<AuthorizedRoutes /> ponent', () => {
it('should render', () => {
const tree = toJson(wrapper);
expect(tree).toMatchSnapshot();
expect(wrapper).toHaveLength(1);
});
it('should contain a Main ponent', () => {
expect(wrapper).find(Main).toHaveLength(1);
});
});
Summary of all failing tests FAIL client/containers/Routes/AuthorizedRoutes.test.js
AuthorizedRoutes ponent › should contain a Main ponent
TypeError: expect(...).find is not a function
Why is .find
not a function in the code context below?
import React from 'react';
import { shallow } from 'enzyme';
import toJson from 'enzyme-to-json';
import { AuthorizedRoutesJest } from './AuthorizedRoutes';
// Components
import {
Main
} from '../../ponents';
const wrapper = shallow(<AuthorizedRoutesJest />);
describe('<AuthorizedRoutes /> ponent', () => {
it('should render', () => {
const tree = toJson(wrapper);
expect(tree).toMatchSnapshot();
expect(wrapper).toHaveLength(1);
});
it('should contain a Main ponent', () => {
expect(wrapper).find(Main).toHaveLength(1);
});
});
Share Improve this question asked Nov 20, 2017 at 15:08 Leon GabanLeon Gaban 39.1k122 gold badges349 silver badges550 bronze badgesSummary of all failing tests FAIL client/containers/Routes/AuthorizedRoutes.test.js
AuthorizedRoutes ponent › should contain a Main ponent
TypeError: expect(...).find is not a function
2 Answers
Reset to default 6I was using .find
incorrectly
Here is an example of how to use find:
it('should contain a ConnectedRouter ponent', () => {
expect(wrapper.find(ConnectedRouter)).toHaveLength(1);
});
it('should contain a Switch ponent', () => {
expect(wrapper.find(Switch)).toHaveLength(1);
});
it('should contain 7 Route ponents', () => {
expect(wrapper.find(Route)).toHaveLength(7);
});
This is in addition if you want to find a ponent with specific testID props
it('should render the date when the message was sent', () => {
expect(chatBubbleComponent.findWhere((node) => node.prop('testID') === 'chat_sent_at')).toHaveLength(1);
});
本文标签: javascriptEnzyme test TypeError expect()find is not a functionStack Overflow
版权声明:本文标题:javascript - Enzyme test: TypeError: expect(...).find is not a function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742337237a2455867.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论