我对文本字段中的更改进行单元测试完全迷失了方向。我使用jest +酶来更改文本字段,但是policyEffectiveField.props().value总是空的。
我尝试过模拟,但在中使用了'change‘和'click’。
policyEffectiveField.simulate('change', {
// you must add this next line as (Formik calls e.persist() internally)
persist: () => {},
// simulate changing
我一直在努力用我的简单形式来编写测试:
import { useFormik } from 'formik';
import * as yup from 'yup';
import Button from '@mui/material/Button';
import TextField from '@mui/material/TextField';
import dayjs from 'dayjs';
import Stack from '@mui/material/Stack';
import {
嗨,我在组件中使用Formik,其中的方法调用如下所示
addMetadata(values) {
console.log(values);
let newState = update(this.state, {
pro: { $set: values}
});
console.log(newState); // this point result print as expected
this.setState(newState);
console.log(this.st
当我单击按钮提交表单时,会收到以下警告:
Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
Formik@http://localhost:3000/static/js/vendors