`simulate` - 测试失败,无法找出问题所在

`simulate` - Fails on testing, Not able to figure out the issue

我使用 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("");
  });
});

Live Demo

您在组件中输入错误

handleChange = event => {
  this.setState({ comment: event.target.vaue });
};

应该是value不是vaue