我universal-cookie用来存储在本地存储中,然后通过管道传输到商店.
class App extends Component {
componentDidMount() {
// if a cookie is present, save the value in the store for use communication
// with the server. If the cookie is undefined, the user is redirected to the login page.
// Redirection is handled by router.
const userNameInCookie = cookies.get('userName');
if (userNameInCookie) {
this.props.dispatch(actions.setUserNameFromCookie(userNameInCookie));
}
}
render() {
return (
<div>
<div className="header">
<h2 className="header-title">Traveler</h2>
</div>
{this.props.children}
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行Jest测试套件时,每次测试都会因此错误而失败
FAIL src/test/UserCreateForm.test.js
? Test suite failed …Run Code Online (Sandbox Code Playgroud) 当我尝试调用generateHash我在 User 模型上定义的实例方法时出现以下错误:
User.generateHash(...).then is not a function
这是模型定义本身:
const User = sequelize.define('User',
{
firstName: {
type: Sequelize.TEXT,
field: 'first_name'
},
lastName: {
type: Sequelize.TEXT,
allowNull: false,
field: 'last_name'
},
userName: {
type: Sequelize.TEXT,
field: 'user_name',
allowNull: false
},
password: {
type: Sequelize.TEXT,
allowNull: false
}
}, {
tableName: 'users',
underscored: true,
classMethods: {
associate: function(models) {
User.hasMany(
models.Trip,
{
as: 'trips',
foreignKey: {
name: 'userId',
field: 'user_id',
allowNull: false
},
onDelete: 'CASCADE'
});
},
},
instanceMethods: { …Run Code Online (Sandbox Code Playgroud)