我有以下Jasmine测试,不幸的是,我未能成功运行。事实上,第二次测试失败了,第一次测试通过了。问题是一次只能通过一次测试。如果我评论掉第一个测试,第二个测试有效,反之亦然。可能是什么问题?提前感谢的帮助
describe('Roles Spec', function() {
'use strict';
let helper = require('./helper');
let Role = require('../server/models/roles');
beforeEach(function(done) {
// Empty the DB then populate it with 3 roles
helper.clearDb(function() {
helper.seedRoles(done);
});
});
it('beforeEach should be called before each test', function(done) {
Role.find().exec().then(function(roles) {
expect(roles.length).toBe(3);
done();
})
});
it('beforeEach should be called before each test', function(done) {
Role.find().exec().then(function(roles) {
expect(roles.length).toBe(3);
done();
})
});
});
我刚刚发现问题出在我的clearDB
函数上,它运行不正常。
这就是最终起作用的clearDB
函数:
// helpers.js
exports.clearDb = function(next) {
Role.remove({}, function(err) {
console.log('collection removed');
next();
});
};
希望这能帮助任何可能在未来中遇到类似情况的人