How Can I Pass Mochas Done Callback Function To Another Helper Function
I have a block of code that I will be using several times within a then statement in mocha so I turned it into a function. However I also need to call done()within that function an
Solution 1:
You're overthinking it - mocha supports promises, you can return a promise and if it is fulfilled the test will pass (and if the expects throw it will fail):
var collectionChecker = function(results) {
expect(Array.isArray(results), 'Did not return collection');
expect(results.length === numAttr, 'Returned wrong number of models');
};
// just add a return, no `done` here or anywhere
test('returns a collection with correct number of models', function() {
return attrs.getAttributeTemplates().then(collectionChecker);
});
Post a Comment for "How Can I Pass Mochas Done Callback Function To Another Helper Function"