我正在尝试用 Jest 和 Enzyme 在 React 上编写测试。但在调用.simulate('change')函数时,该值保持不变NULL,不会更改为预期值miqueias@gmail.com。我的应用程序.jsx:
const App = () => {
const [username, setUsername] = React.useState(null);
const [password, setPassword] = React.useState(null);
const handleChange = (event) => {
setUsername(event.target.value);
};
return (
<div
style={{
height: "100vh",
display: "flex",
flexDirection: "column",
justifyContent: "center",
alignItems: "center",
}}
>
<input
type="email"
id="email"
value={username}
onChange={handleChange}
/>
<input
type="password"
id="password"
value={password}
onChange={(event) => setPassword(event.target.value)}
/>
<button>Enviar</button>
</div>
);
};
export default App;
Run Code Online (Sandbox Code Playgroud)
我的应用程序.test.js:
import React from 'react';
import …Run Code Online (Sandbox Code Playgroud)