const Sequelize = require('sequelize');
var player = sequelize.define('player', {
title: {
type: Sequelize.STRING
},
mess: {
type: Sequelize.STRING
},
content: {
type: Sequelize.STRING
}
}, {
freezeTableName: true
});
这里给出了我没有定义模型的错误。但是模型已经定义了。
答案 0 :(得分:0)
如果您想模拟单元测试的续集模型,最好的方法是使用sequelize-mock。写答案时的版本是0.10.2
以下是如何使用它的示例from their documentation:
// Import the mock library
var SequelizeMock = require('sequelize-mock');
// Setup the mock database connection
var DBConnectionMock = new SequelizeMock();
// Define our Model
var UserMock = DBConnectionMock.define('users', {
'email': 'email@example.com',
'username': 'blink',
'picture': 'user-picture.jpg',
}, {
instanceMethods: {
myTestFunc: function () {
return 'Test User';
},
},
});
// You can also associate mock models as well
var GroupMock = DBConnectionMock.define('groups', {
'name': 'My Awesome Group',
});
UserMock.belongsTo(GroupMock);
// From there we can start using it like a normal model
UserMock.findOne({
where: {
username: 'my-user',
},
}).then(function (user) {
// `user` is a Sequelize Model-like object
user.get('id'); // Auto-Incrementing ID available on all Models
user.get('email'); // 'email@example.com'; Pulled from default values
user.get('username'); // 'my-user'; Pulled from the `where` in the query
user.myTestFunc(); // Will return 'Test User' as defined above
user.getGroup(); // Will return a `GroupMock` object
});