酶测试:TypeError:expect(...)。find不是函数

编程入门 行业动态 更新时间:2024-10-22 02:47:11
本文介绍了酶测试:TypeError:expect(...)。find不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

为什么 .find 在下面的代码上下文中不是函数?

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 '../../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); }); });

所有失败测试的摘要失败的客户端/容器/ Routes / AuthorizedRoutes.test.js

Summary of all failing tests FAIL client/containers/Routes/AuthorizedRoutes.test.js

AuthorizedRoutes组件›应该包含一个主要组件

AuthorizedRoutes component › should contain a Main component

TypeError:Expect(。 ..)。find不是函数

TypeError: expect(...).find is not a function

推荐答案

我正在使用。错误地找到

以下是使用find的示例:

Here is an example of how to use 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); });

更多推荐

酶测试:TypeError:expect(...)。find不是函数

本文发布于:2023-10-30 04:15:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1541734.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   测试   expect   TypeError   find

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!