This repository was archived by the owner on May 29, 2019. It is now read-only.
This repository was archived by the owner on May 29, 2019. It is now read-only.
Should destroy all models properly when they are provided with givenModel as an Array. #54
Open
Description
When a model is initialised with an Array, the model instances can be created properly, but an Error will be thrown when the helper
tries to destroy them. For example, the following code created to model instances:
helpers.beforeEach.givenModel('xxx-test-model', [{name: 'name0'}, {name: 'name1'}]);
The afterEach method willl fail because the array does not have a destroy method:
this[modelKey].destroy(done);
we should test if it is an array and handle it properly. E.g.
function _destroy(aModel, cb) {
aModel.destroy(cb);
}
afterEach(function(done) {
var model = this[modelKey];
if (Object.prototype.toString.call(model) === '[object Array]') {
async.each(
model,
_destroy.bind(this),
done);
} else {
model.destroy(done);
}
});
Metadata
Metadata
Assignees
Labels
No labels