0
일부 코드를 테스트하기 위해 재스민을 사용하고 있습니다. 마지막 주장을 제외하면 모든 것이 잘 작동합니다. 누군가 나를 도울 수 있습니까?Jasmine : 내 콜백에 내 어설 션이 실행되지 않는 이유
var mongoose = require("mongoose")
, db = mongoose.connect('mongodb://localhost/database')
, Schema = mongoose.Schema;;
describe('Lockmanager', function() {
var status;
var Test = new Schema({
name: String
});
var testModel = mongoose.model('Test', Test);
var LockManager = require('locks').buildLockManager().getManager(testModel, 10000);
var newTestModel = new testModel({
name: "Test"
});
it('should set a lock on an arbitrary mongoose model', function() {
this.after(function() {
testModel.remove({}, function(err, numAffected) {
status = 'collectionRemoved';
});
});
runs(function() {
newTestModel.save(function(err) {
expect(err).toBeNull();
status = 'hasBeenSaved';
});
});
waitsFor(function() {
return status == 'hasBeenSaved';
});
runs(function() {
LockManager.requestLock(newTestModel._id, function(err, response) {
expect(err).toBeNull();
status = 'readyToBeReleased';
});
});
waitsFor(function() {
return status == 'readyToBeReleased';
});
runs(function() {
LockManager.releaseLock(newTestModel._id, function(err) {
expect(err).toBeNull();
status = 'readyToBeDeleted';
});
});
waitsFor(function() {
return status == 'readyToBeDeleted';
})
});
it('should delete all test entries after the test', function() {
waitsFor(function() {
return status == 'collectionRemoved';
});
runs(function() {
testModel.find({}, function(err, res) {
expect(res.length).toEqual(0);
status = 'allDone';
});
});
/*** This waitsFor fixed the problem ***/
waitsFor(function() {
return status == 'allDone';
});
});
});
결과 로그이있다 : 위한
자스민 노드 사양/lockmanager.spec.js 잠금 '4fabcae0b563859269000001은'획득되었다. . '4fabcae0b563859269000001'에 대한 잠금이 해제되었습니다. .
는 0.031 초 2 개 테스트 3 주장 0 고장이 실행 된에서 마무리.