I have the following Jasmine tests, which I unfortunately have not been able to run successfully. As it is, the second test is failing and the 1st one is passing. The issue is that only one test passes at a time. If I comment out the first test, the second one works and vice versa. What could be the problem? Thanks in advance for your help
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();
})
});
});
I just found out that the problem was with my clearDB
function which wasn't running properly.
This is the clearDB
function that eventually worked:
// helpers.js
exports.clearDb = function(next) {
Role.remove({}, function(err) {
console.log('collection removed');
next();
});
};
Hope this helps anyone who might run into a similar situation in future
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.