我正在尝试为我的登录表单实现纯函数,并且我正在使用 redux-form。
我在单元测试中遇到了这个错误:
Invariant Violation: Element type is invalid: expected a string or a class/function but got: undefined.
这是我要测试的组件:
import { Username } from './presentation/LoginPage.js';
export class LoginPage extends React.Component {
render() {
const { error, handleSubmit, pristine, reset, submitting } = this.props;
return (
<form onSubmit={handleSubmit}>
<div>
<label>Username</label>
<Field
name="username"
component={username =>
<Username username />
} />
</div>
</form>
);
}
}
LoginPage.propTypes = {
};
export default reduxForm({
form: 'login', // a unique identifier for this form
})(LoginPage);
这是我的纯组件:
export const Username = (props) => {
const { username } = props;
return (
<div>
<input type="text" {...username} placeholder="Username" />
{username.touched && username.error && <span>{username.error}</span>}
</div>);
};
当我在浏览器中播放它时,我得到了reduce is not defined
. 当我删除它时它工作正常<Field />
我错过了什么明显的东西吗?