mardi 1 décembre 2015

Mocha/Chai tests hanging at .should.be.deep.equal despite result existing

I'm running some tests using Mocha and chai. One of the tests is hanging at a .should.be.deep.equal call.

Here's the test code:

// 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);
            });
        })
    })
});

And here's the function it's testing:

exports.locationList = function(req, callback) {
listLocations().then(
    function(data) {
        callback(data);
    },
    function(err) {
        console.log('Error Retrieving Location Information: ' + err);
        callback(err);
    });
};

As I note in the comments, the results object exists and gets printed to the console. results.should.exist; doesn't throw an exception and if I comment out everything but it the test works fine. For some weird reason, despite both the testData.locationList and result object existing, the test times out. I have 14 other tests that use the exact same syntax without any problems. Does anyone know what could be causing this to happen for this specific test?

Here's the output from the tests:

Testing the functions that deal with users and locations:
    function locationList                            
        [ { devices: {},
            address: '123 Fake St, Waterloo, On',
            location: 'Unittest',
            owner: 'unit@test.com',
            _id: '-1' } ]         
        [ { devices: {},
            address: '123 Fake St, Waterloo, On',
            location: 'Unittest',
            owner: 'unit@test.com',
            _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)   

Extending the timeout doesn't work. Nor does putting something random (ie. the integer 1 in the .should.be.deep.equal() function.

Aucun commentaire:

Enregistrer un commentaire