用伊斯坦布尔加载猫鼬模型

时间:2014-07-14 18:29:14

标签: node.js mongodb mongoose istanbul

我想为我们的项目实现代码覆盖,所以我们使用grunt-istanbul。 我坚持这个教程:https://github.com/taichi/grunt-istanbul

我的问题是,在针对工具化源代码运行测试时出现此错误,但在针对正常代码运行测试时它可以正常工作。

>> Mocha exploded!
>> MongooseError: Schema hasn't been registered for model "Comm".
>> Use mongoose.model(name, schema)
>>     at Mongoose.model (/Users/user/repos/review.ninja/node_modules/mongoose/lib/index.js:322:13)
>>     at Object.<anonymous> (/Users/user/repos/review.ninja/test/coverage/instrument/src/server/api/comm.js:9:147)
>>     at Module._compile (module.js:449:26)
>>     at Object.Module._extensions..js (module.js:467:10)
>>     at Module.load (module.js:349:32)
>>     at Function.Module._load (module.js:305:12)
>>     at Module.require (module.js:357:17)
>>     at require (module.js:373:17)
>>     at /Users/user/repos/review.ninja/node_modules/grunt-mocha-test/node_modules/mocha/lib/mocha.js:172:27
>>     at Array.forEach (native)
>>     at Mocha.loadFiles (/Users/user/repos/review.ninja/node_modules/grunt-mocha-test/node_modules/mocha/lib/mocha.js:169:14)

我们还在comm模块中导出mongoose.model('Comm', CommSchema);并将其导入测试代码中。如前所述,如果正常运行Mocha测试,它会起作用。

0 个答案:

没有答案