나는 Nodejs + Mongoose + MongoDB 웹 애플리케이션을 구축하고 있으며, 재스민 유닛 테스트 프레임 워크로 DAO 메소드를 단위 테스트하려고합니다. 나는이 같은 함수를 호출 내 컨트롤러에 다음 코드몽구스 Jasminejs 유닛 테스트 crud methods (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);
}
});
};
에게이 모든 프로파일을 표시 할 책임이 내 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);
:
내 모델은 다음과 같다 :
$scope.afficherProfils = function() {
$http.get('/listerProfil')
.success(function(data) {
$scope.listeProfils = data;
});
};
어떻게 이런 종류의 기능을 테스트 할 수 있습니까? 일부 요소를 mongoDB 데이터베이스에 삽입하고 함수가 정보를 얻는 지 테스트 할 수 있습니까? 이런 종류의 단위 테스트에는 이전 경험이 없습니다.
많은 도움을 주신 덕분에 – badaboum