酶测试:TypeError:expect(...)。find不是函数 [英] Enzyme test: TypeError: expect(...).find is not a function

查看:93
本文介绍了酶测试: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不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆