【发布时间】:2019-09-17 23:40:27
【问题描述】:
所以我需要帮助来编写测试以正确传递给子组件的道具。
beforeEach(() => {
wrapped = shallow(
<CommentDetail
author="Sam"
timeAgo="Today at 4:45 pm"
content="nice blog post"
avatar="https://s3.amazonaws.com/uifaces/faces/twitter/m_kalibry/128.jpg"
/>
);
});
it("renders author's name", () => {
expect(wrapped.find(".author").prop("author")).toEqual("Sam");
});
// snippet from the react file
<a href="/" className="author">
{author}
</a>
这似乎与我在文档中找到的非常相似,但在测试输出中收到的值中出现了未定义的值。
可以编写另一个测试,但我不确定它是否正确测试了道具:
it("renders author's name", () => {
expect(wrapped.render().find(".author").text()).toContain("Sam");
});
【问题讨论】:
标签: reactjs typescript jestjs enzyme