gpt4 book ai didi

javascript - enzyme 测试 : TypeError: expect(. ..).find 不是函数

转载 作者:行者123 更新时间:2023-11-28 20:22:11 25 4
gpt4 key购买 nike

为什么 .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);
});
});

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

AuthorizedRoutes component › should contain a Main component

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

最佳答案

我错误地使用了 .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);
});

关于javascript - enzyme 测试 : TypeError: expect(. ..).find 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47395098/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com