我使用 进行了简单的测试jest
,一切正常,只需要一个问题。我收到一个错误
expect(wrapper.find("textarea").prop("value")).toEqual("new comment");
fails.
无法弄清楚这个问题。有人帮我吗?
这是我的测试代码:
import React from "react";
import { mount } from "enzyme";
import CommentBox from "components/CommentBox";
let wrapper;
beforeEach(() => {
wrapper = mount(<CommentBox />);
});
afterEach(() => {
wrapper.unmount();
});
it("has a text area and button", () => {
expect(wrapper.find("textarea").length).toEqual(1);
expect(wrapper.find("button").length).toEqual(1);
});
describe("the text area", () => {
beforeEach(() => {
wrapper.find("textarea").simulate("change", {
target: { value: "new comment" }
});
wrapper.update();
});
it("has a text area that users can type in ", () => {
expect(wrapper.find("textarea").prop("value")).toEqual("new comment");
});
it("when form is submitted, text area gets emptied", () => {
wrapper.find("form").simulate("submit");
wrapper.update();
expect(wrapper.find("textarea").prop("value")).toEqual("");
});
});