不能在sailsjs中unit testing我的模型

对于我的帆应用程序,我使用下面的代码来unit testing用户模型,但得到了错误信息:

'TypeError:对象#没有方法'创build''

var User = require('../../api/models/User'); var Sails = require('sails'); console.log(User); describe("User Model:", function() { // create a variable to hold the instantiated sails server var app; // Global before hook before(function(done) { // Lift Sails and start the server Sails.lift({ log: { level: 'error' }, }, function(err, sails) { app = sails; done(err, sails); }); }); // Global after hook after(function(done) { app.lower(done); }); describe("Password encryption", function() { describe("for a new user", function() { var user; before(function (cb) { var userData = { email: "testuser@sails.com", password: "test_password", passwordConfirmation: "test_password" }; User.create(userData, function (err, newUser) { if (err) return cb(err); user = newUser; cb(); }); }); it("must encrypt the password", function() { user.must.have.property('encryptedPassword'); user.must.not.have.property('password'); user.must.not.have.property('passwordConfirmation'); }); after(function (cb){ user.destroy(function (err) { cb(err); }); }); }); 

在我看来,帆是正确解除,造成创build方法不可用的问题是什么?

删除第一行:

 var User = require('../../api/models/User'); 

一旦Sails应用程序被解除,您将自动获得您的模型,例如,请参阅此处 。

而在你的情况下,你的第一行覆盖了用Sails.js构build的User模型,这就是为什么即使你有一个对象,它不是一个水线模型。