gpt4 book ai didi

javascript - React/Enzyme 测试 HTML 标签的值(value)?

转载 作者:行者123 更新时间:2023-12-03 00:42:34 24 4
gpt4 key购买 nike

我想测试我的标签组件是否正确解析主体对象中的数据。

这是我的标签:

<label id="userInfo"><b>Logged in as: </b>{principal.emailAddress}, <b>Role: </b>{userRole}</label>

这是我的测试,目前不起作用:

describe("Testing User Info displaying correctly", () =>{
it("when provided principal data, it should correctly combine the username and role", () => {
expect(wrapper.find('[data-test-id="userInfo"]').text()).to.equal("Logged in as: jdoe@foo.bar, Role: Subscriber");
});
});

如何检查标签的值(或更准确地说,标签之间的文本)是否正确显示?

当前测试失败并显示以下消息:

"Method “text” is only meant to be run on a single node. 0 found instead."

最佳答案

有了这个reference ,expect语句应该像下面这样:

expect(wrapper.find('[data-test-id="userInfo"]').text().equals("Logged in as: jdoe@foo.bar, Role: Subscriber")).to.equal(true);

关于javascript - React/Enzyme 测试 HTML 标签的值(value)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53387323/

24 4 0