Я использую некоторые тесты с использованием Mocha и chai. Один из тестов висит на вызове .should.be.deep.equal
.Mocha/Chai тесты висят на .should.be.deep.equal несмотря на существующий результат
Вот код теста:
// Make the fake connection before running tests
before(function(done) {
mongoose.connect('mongodb://fake.test/TestingDB', function(err) {
done(err);
});
});
// Test Cases
describe('Testing the functions that deal with users and locations:', function() {
// Test Setup
var req = {};
beforeEach(function(done) {
mockgoose.reset()
async.parallel([function(callback){
sensors.create(testData.deviceData, function(err, model) {
if (err) {console.log(err)}
callback();
});
}, function(callback) {
locations.create(testData.locationData, function(err, model) {
if (err) {console.log(err)}
callback();
});
}], function(err) {
done();
});
});
afterEach(function(done) {
mockgoose.reset();
done();
});
// Tests
describe('function locationList', function() {
it('should list the test location', function(done) {
dbFunctions.locationList(req, function(result) {
console.log(result) //Prints the whole result
console.log(testData.locationList)
result.should.exist; //This doesn't cause it to hang
result.should.be.deep.equal(testData.locationList) //hangs here
done(result);
});
})
})
});
А вот функция это тестирование:
exports.locationList = function(req, callback) {
listLocations().then(
function(data) {
callback(data);
},
function(err) {
console.log('Error Retrieving Location Information: ' + err);
callback(err);
});
};
Как я отмечаю в комментариях, объект результатов существует и печатается на консоль. results.should.exist;
не генерирует исключение, и если я прокомментирую все, но это испытание отлично работает. По какой-то странной причине, несмотря на то, что существующий объект testData.locationList
и result
, тест истекает. У меня есть 14 других тестов, которые без каких-либо проблем используют тот же синтаксис. Кто-нибудь знает, что может привести к тому, что это произойдет для этого конкретного теста?
Вот выход из тестов:
Testing the functions that deal with users and locations:
function locationList
[ { devices: {},
address: '123 Fake St, Waterloo, On',
location: 'Unittest',
owner: '[email protected]',
_id: '-1' } ]
[ { devices: {},
address: '123 Fake St, Waterloo, On',
location: 'Unittest',
owner: '[email protected]',
_id: '-1' } ]
1) should list the test location
0 passing (2s)
1 failing
1) Testing the functions that deal with users and locations: function locationList should list the test location:
Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.
at null.<anonymous> (C:\Users\My Name\AppData\Roaming\npm\node_modules\mocha\lib\runnable.js:189:19)
Расширение тайм-аут не работает. Также не положить что-то случайное (то есть целое число 1
в функции .should.be.deep.equal()
Я не думаю, что это исправление для вашей проблемы, но вы, вероятно, должны просто вызвать done() вместо done (result), поскольку все, что передано done(), будет интерпретироваться как ошибка. –