我正在为我的nodeJS
应用编写测试,以检查sequelize
模型是否具有所有定义的属性。
运行测试时,我收到关于未定义上下文的错误。
我正在使用以下库来帮助检查模型。 sequelize-test-helpers
此错误是否是由于我未正确定义的Mocha
引发的?
// Model
'use strict'
const model = (sequelize, DataTypes) => {
const Communications = sequelize.define(
'Communications',
{
recordID: {
primaryKey: true,
type: DataTypes.INTEGER,
autoIncrement: true
},
messageUUID: {
type: DataTypes.UUID,
unique: true,
},
firstName: {
type: DataTypes.STRING
},
lastName: {
type: DataTypes.STRING
},
age: {
type: DataTypes.INTEGER
},
department: {
type: DataTypes.STRING
},
campus: {
type: DataTypes.STRING
},
state: {
type: DataTypes.STRING
},
partition: {
type: DataTypes.INTEGER
},
offset: {
type: DataTypes.INTEGER
}
})
return Communications
}
module.exports = model
// Test
describe('models/Communication', function () {
const Comm = Communication(sequelize, dataTypes)
const comm = new Comm()
checkModelName(Comm)('Communications')
context('properties', function () {
;['recordID', 'messageUUID', 'firstName', 'lastName', 'age', 'department', 'campus', 'state', 'partition', 'offset'].forEach(
checkPropertyExists(comm)
)
})
});
Error Returned = ReferenceError: context is not defined
答案 0 :(得分:1)
代替上下文来描述您是否不使用摩卡,因为上下文是摩卡的同义词。
在这里检查sequelize-test-helpers的其中一位贡献者的相同答案
https://github.com/davesag/sequelize-test-helpers/issues/111