使用上下文时出现 MochaJS 错误 - 接收未定义的实例
MochaJS Error when using Context - receiving undefined instance
我正在为我的 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
如果您不使用 mocha,请将 context 替换为 describe,因为 context 是 mocha 的同义词。
在此处查看 sequelize-test-helpers
的一位贡献者的相同答案
https://github.com/davesag/sequelize-test-helpers/issues/111
我正在为我的 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
如果您不使用 mocha,请将 context 替换为 describe,因为 context 是 mocha 的同义词。
在此处查看 sequelize-test-helpers
的一位贡献者的相同答案https://github.com/davesag/sequelize-test-helpers/issues/111