0

I'm trying to write some unit tests to test some functionalities implemented with Cloud Code. Below is my code. However it seems Mocha does not wait until the Cloud Code response is received and immediately exits from the test:

var chai = require('chai');
var expect = chai.expect;

var Parse = require('parse/node').Parse;

Parse.initialize("", "");

describe('MyTest', function() {
  it('Number of cart items should be greater than 0', function() {
    var cartSummary = 0;

        var CartItem = Parse.Object.extend('CartItem');
        var query = new Parse.Query(CartItem);
        query.find({
            success: function(results) {
                expect(results).to.have.length(3);
            },
            error: function(error) {
                console.log("Error: " + error.code + " " + error.message);
            }
        });
  });
});
  • Possible duplicate of [Testing asynchronous function with mocha](http://stackoverflow.com/questions/12159846/testing-asynchronous-function-with-mocha) You should read the docs for this stuff! – Robert Moskal May 03 '16 at 02:57
  • https://github.com/WhoopInc/supertest-as-promised – Daniel Lizik May 03 '16 at 02:57

0 Answers0