我正在尝试使用enzyme
来测试我的组件。你能否告诉我为什么我会收到错误“无法读取属性'有'未定义
“
这是我的代码
https://codesandbox.io/s/oq7kwzrnj5
import React from "react";
import { shallow, mount } from "enzyme";
import Counter from "./Counter";
describe("counter", () => {
it("test truty", () => {
const wrapper = shallow(<Counter />);
expect(wrapper.find("p")).to.have.length(1);
});
});
答案 0 :(得分:0)
当您使用jest时,该行应如下所示:
expect(wrapper.find("p").length).toBe(1);
或
expect(wrapper.find('p').exists()).toBe(true)
答案 1 :(得分:0)
在代码演示中,您正在使用酶3.x ,并且在该版本中 已不再可用。
尝试使用 2.x。版本,或更改 3.x 的预期条款,例如:
expect(wrapper.find("p")).toHaveLength(1);