[{"p_id" : 1,"author": "X1","editor": "X2"},{"p_id" : 2, "author": "Y1"},{"p_id" : 3,"author": "Z1","editor": "Z2"},{...
print("Vector: ", cvss3_v.group())
import { BrowserRouter as Router } from "react-router-dom";
wrapper.state('email')应该返回了email@email.com,但未更新。任何原因?
答案 0 :(得分:1)
您需要在模拟事件中传递id
:
emailInput.simulate("change", {
target: {
id: "your id here"
value: "email@email.com"
}
});
此外,由于更新是异步完成的,因此在执行任何断言之前,您应该等待诺言。
定义一个flushPromises
函数:
function flushPromises() {
return new Promise(resolve => setImmediate(resolve));
}
然后等待测试中的承诺:
test("Rendered email input and test valid", () => {
const email = "";
const wrapper = setup(null, { email });
const emailInput = findByTestAttribute(
wrapper,
someId
);
emailInput.simulate("change", { target: { id: "your id here", value: "email@email.com" } });
await flushPromises; // await for promises to return
console.log(wrapper.state('email')) //Empty ""
expect(wrapper.state("email")).toBe("email@email.com");
});