Comments on: sailsjs testing: how to truncate the database /2016/06/sailsjs-testing-patterns-trunctate-database/ Sarah Allen's reflections on internet software and other topics Sun, 24 Jun 2018 14:16:13 +0000 hourly 1 https://wordpress.org/?v=5.7.1 By: Bernardo Gomes /2016/06/sailsjs-testing-patterns-trunctate-database/#comment-8058 Sun, 24 Jun 2018 14:16:13 +0000 /?p=5990#comment-8058 afterEach(function(done) {

function createDestroyCallbackFunction(element, index, array) {

return function(callback) {

sails.models[element].destroy({})

.exec(function(err) {

callback(null, err)

});

};

}

var destroyFuncs = Object.keys(sails.models).map(createDestroyCallbackFunction);

async.parallel(destroyFuncs, function(err, results) {

done(err);

});

});

]]>
By: Bernardo Gomes /2016/06/sailsjs-testing-patterns-trunctate-database/#comment-8057 Sun, 24 Jun 2018 14:15:20 +0000 /?p=5990#comment-8057 Hi,

I found some erro in second code:

this -> for (modelName in sails.models).

When the function is executed the last model is used for all models.

(each loop override the value of variable.)

For fix this I change the function for this: FOR TO MAP.

afterEach(function(done) {

function createDestroyCallbackFunction(element, index, array) {

return function(callback) {

sails.models[element].destroy({})

.exec(function(err) {

callback(null, err)

});

};

}

var destroyFuncs = Object.keys(sails.models).map(createDestroyCallbackFunction);

async.parallel(destroyFuncs, function(err, results) {

done(err);

});

});

]]>
By: khangdinh /2016/06/sailsjs-testing-patterns-trunctate-database/#comment-5483 Thu, 05 Jan 2017 12:48:39 +0000 /?p=5990#comment-5483 this helped me :) Thanks for sharing!

]]>