Mongodb Mongoose Jasminejs单元测试积垢法(DAO)

Mongodb Mongoose Jasminejs单元测试积垢法(DAO),mongodb,unit-testing,angularjs,jasmine,Mongodb,Unit Testing,Angularjs,Jasmine,我正在构建一个Nodejs+Mongoose+MongoDB web应用程序,并尝试使用Jasmine单元测试框架对我的DAO方法进行单元测试 我的模型如下: var mongoose = require('mongoose'); var Schema = mongoose.Schema; var profilSchema = new Schema({ photo: {type: String}, nom: {type: String , required: true}, type: { t

我正在构建一个Nodejs+Mongoose+MongoDB web应用程序,并尝试使用Jasmine单元测试框架对我的DAO方法进行单元测试

我的模型如下:

var mongoose = require('mongoose');

var Schema = mongoose.Schema;

var profilSchema = new Schema({
photo: {type: String},
nom: {type: String , required: true},
type: { type: String , required: true},
descriptif: {type: String, required: true},
niveauScolaire: {type: String , required: true},

});

/**
* Statics
*/
 profilSchema.statics = {
load: function(id, cb) {
    this.findOne({
        _id: id
    }).exec(cb);
}
  };

  var Profil = mongoose.model('Profil', profilSchema);
在负责显示所有概要文件的DAO函数中,我有以下代码

/**
 * List of Profiles
 */
  exports.all = function(req, res) {
   Profil.find().exec(function(err, profils) {
    if (err) {
        res.render('error', {
            status: 500
        });
    } else {
        // console.log(profils._id);
        res.jsonp(profils);
    }
});
};
在我的控制器中,我调用如下函数:

    $scope.afficherProfils = function() {
    $http.get('/listerProfil')
        .success(function(data) {
        $scope.listeProfils = data;

    });

};
如何测试这类函数?是否可以将一些元素插入mongoDB数据库并测试函数是否获得信息?
我以前确实没有这种单元测试的经验。

您必须分别测试服务器端和客户端功能

Angularjs位将在浏览器中运行。您可以使用或运行客户端测试。您不需要在测试中发出实际的http请求。你可以控制自己的行为

看一看如何编写jasmine测试,并深入angularjs文档,以便更好地理解如何为angularjs编写单元测试和e2e测试

进一步阅读材料:

js位将在服务器端运行,您可以使用它来运行服务器端测试。许多项目使用单独的测试数据库进行测试,它们在测试套件运行之前使用测试数据填充数据库,然后在测试运行完成后清理数据库