小编Miq*_*des的帖子

酶模拟更改输入不会更改 React Hooks 上的值

我正在尝试用 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)

unit-testing reactjs jestjs enzyme react-hooks

0
推荐指数
1
解决办法
4569
查看次数

标签 统计

enzyme ×1

jestjs ×1

react-hooks ×1

reactjs ×1

unit-testing ×1