對於我的船帆的應用程序,我用下面的代碼進行單元測試的用戶模型,模型,但得到的錯誤消息:不能單元測試我在sailsjs
「類型錯誤:對象#有沒有方法'創建」
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: "[email protected]",
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);
});
});
});
在我看來,帆正確解除了,導致創建方法不可用的問題是什麼?
我對nodejs很陌生,試圖爲我正在構建的應用程序編寫一些測試。是否有可能看看你的模型,以便我可以嘗試弄清楚如何爲我的模型編寫測試。謝謝 – kushaldsouza