import { BrowserRouter as Router } from "react-router-dom";
const setup = (props = {}, state = null,initialState={}) => {
const store = storeFactory(initialState);
const wrapper = mount(
<Router
<Component {...props} store={store}/>
</Router>
);
if (state) wrapper.setState(state);
return wrapper;
};
test("Rendered email input and test valid", () => {
const email = "";
const wrapper = setup(null, { email });
const emailInput = findByTestAttribute(
wrapper,
someId
);
emailInput.simulate("change", { target: { value: "[email protected]" } });
console.log(wrapper.state('email')) //Empty ""
expect(wrapper.state("email")).toBe("[email protected]");
});
wrapper.state('email')应该已经返回[email protected],但未更新。任何原因?
您需要在模拟事件中传递id
:
emailInput.simulate("change", {
target: {
id: "your id here"
value: "[email protected]"
}
});