- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
每当我尝试运行 jest 时,我都会收到以下错误:
类型错误:无法读取未定义的属性“当前”
这是被测代码:
import React, { Component } from 'react';
import { withFormik } from 'formik';
import { toast } from 'react-toastify';
import { Field } from 'formik';
import * as Yup from 'yup';
import api from '../../api';
import TextInput from '@components/common/forms/TextInput';
import Checkbox from '@components/common/forms/Checkbox';
import CheckboxGroup from '@components/common/forms/CheckboxGroup';
import styles from './profile.module.css';
import commonStyles from '@components/common/common.module.css';
import ForgotPassword from '../ForgotPassword';
import Modal from '@components/Modal/Modal';
const formikEnhancer = withFormik({
validationSchema: Yup.object().shape({
firstName: Yup.string()
.min(2, "C'mon, your first name is longer than that")
.required('First name is required'),
lastName: Yup.string()
.min(2, "C'mon, your last name is longer than that")
.required('Last name is required'),
email: Yup.string()
.email('Invalid email address')
.required('Email is required'),
currentPassword: Yup.string(),
password: Yup.string()
.min(8, 'Password has to be at least 8 characters!')
.matches(
/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\\$%\\^&\\*])/,
'Password must contain at least 1 uppercase letter, 1 lowercase letter, 1 number, and 1 special character'
),
confirmPassword: Yup.string().oneOf(
[Yup.ref('password'), null],
'Passwords must match'
),
}),
handleSubmit: (payload, { setSubmitting, setErrors, props }) => {
const user = props.user || JSON.parse(localStorage.getItem('user')).user;
api
.put(`/users/${user._id || user.userId}`, payload, {
withCredentials: true,
})
.then(res => {
toast.success('Your user profile was updated successfully', {
position: toast.POSITION.TOP_CENTER,
hideProgressBar: true,
});
})
.catch(err => {
toast.error('Something went wrong', {
position: toast.POSITION.TOP_CENTER,
hideProgressBar: true,
});
});
setSubmitting(false);
},
mapPropsToValues: ({ user }) => ({
...user,
}),
displayName: 'ProfileForm',
});
class Profile extends Component {
modalProps = {
triggerText: 'Forgot Password?',
};
modalContent = <ForgotPassword user={{ email: '' }} {...this.props} />;
render() {
document.title = 'User Profile';
const {
values,
touched,
errors,
handleChange,
handleBlur,
handleSubmit,
isSubmitting,
isAdmin,
setFieldValue,
} = this.props;
return (
<React.Fragment>
<h2>Profile</h2>
<form onSubmit={handleSubmit}>
<TextInput
id="firstName"
type="text"
label="First Name"
error={touched.firstName && errors.firstName}
value={values.firstName}
onChange={handleChange}
onBlur={handleBlur}
/>
<TextInput
id="lastName"
type="text"
label="Last Name"
error={touched.lastName && errors.lastName}
value={values.lastName}
onChange={handleChange}
onBlur={handleBlur}
/>
<TextInput
id="email"
type="email"
label="Email"
autoComplete="username email"
error={touched.email && errors.email}
value={values.email}
onChange={handleChange}
onBlur={handleBlur}
/>
<TextInput
id="currentPassword"
type="password"
label="Current Password"
autoComplete="current-password"
error={touched.currentPassword && errors.currentPassword}
value={values.currentPassword}
onChange={handleChange}
onBlur={handleBlur}
/>
<div className={styles.forgotPassword}>
<Modal
modalProps={this.modalProps}
modalContent={this.modalContent}
modalButtonClassName={commonStyles.modalLinkButton}
{...this.props}
/>
</div>
<TextInput
id="password"
type="password"
label="New Password"
autoComplete="new-password"
error={touched.password && errors.password}
value={values.password}
onChange={handleChange}
onBlur={handleBlur}
/>
<TextInput
id="confirmPassword"
type="password"
label="Confirm Password"
autoComplete="new-password"
error={touched.confirmPassword && errors.confirmPassword}
value={values.confirmPassword}
onChange={handleChange}
onBlur={handleBlur}
/>
{isAdmin && (
<React.Fragment>
<h3>Roles</h3>
<CheckboxGroup
id="roles"
className={styles.roles}
label="Which of these?"
value={values.roles}
onChange={setFieldValue}
>
<Field
component={Checkbox}
name="roles"
id="admin"
label="Admin"
value="admin"
defaultChecked={values.roles.includes('admin')}
/>
<Field
component={Checkbox}
name="roles"
id="user"
label="User"
value="user"
defaultChecked={values.roles.includes('user')}
/>
<Field
component={Checkbox}
name="roles"
id="family"
label="Family"
value="family"
defaultChecked={values.roles.includes('family')}
/>
<Field
component={Checkbox}
name="roles"
id="friend"
label="Friend"
value="friend"
defaultChecked={values.roles.includes('friend')}
/>
</CheckboxGroup>
</React.Fragment>
)}
<button
type="submit"
disabled={isSubmitting}
className="btn btn-primary"
>
Submit
</button>
</form>
</React.Fragment>
);
}
}
export default formikEnhancer(Profile);
这是测试:
import React from 'react';
import renderer from 'react-test-renderer';
import Profile from '../Profile/Profile';
describe('Profile', () => {
it('renders correctly', () => {
const tree = renderer.create(<Profile />).toJSON();
expect(tree).toMatchSnapshot();
});
});
测试输出提示该行(带有指向创建的小车):
const tree = renderer.create(<Profile />).toJSON();
我在这里做错什么会导致这个错误?
最佳答案
我在这里找到了答案:https://github.com/expo/expo/issues/5268
基本上,您需要在您的 devDependencies 中具有完全相同版本的 react、react-dom 和 react-test-renderer 以避免此错误。
关于testing - Gatsby 测试错误,TypeError : Cannot read property 'current' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61669936/
我只是有一个更琐碎的问题。 为什么undefined == undefined 返回true,而undefined >= undefined 为false? undefined 等于 undefine
用PHP 7.2编写套接字服务器。根据Firefox 60中的“网络”选项卡,服务器的一些HTTP响应的第一行随机变为undefined undefined undefined。因此,我尝试记录套接字
在 JavaScript 中这是真的: undefined == undefined 但这是错误的: undefined <= undefined 起初我以为<=运算符包含第一个,但我猜它试图将其转换
在回答这个问题 (Difference between [Object, Object] and Array(2)) 时,我在 JavaScript 数组中遇到了一些我以前不知道的东西(具有讽刺意味的
来自https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/of , Note: thi
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
当我添加 到我的 PrimeFaces Mobile 页面,然后我在服务器日志中收到以下警告 WARNING: JSF1064: Unable to find or serve resource, u
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我是一名优秀的程序员,十分优秀!