Skip to content

Instantly share code, notes, and snippets.

@Twipped
Created May 20, 2015 23:20
Show Gist options
  • Save Twipped/d8d3448d3e50b62f7e86 to your computer and use it in GitHub Desktop.
Save Twipped/d8d3448d3e50b62f7e86 to your computer and use it in GitHub Desktop.
function makeSequence(test, closures) {
return function () {
if (!closures.length) {
test.ok(false, 'Sequence was invoked too many times.');
throw new Error('Sequence was invoked too many times.');
}
test.ok(true, 'Sequence stepped');
return closures.shift().apply(this, arguments);
};
}
var mocksql = {
query: makeSequence(test, [
function (query, data, cb) {
test.equal(query, 'REPLACE INTO `orders_labeled` SET orderid = ?, labelid = ?');
test.deepEqual(data, [123, 2]);
cb();
},
function (query, data, cb) {
test.equal(query, 'DELETE FROM `orders_labeled` WHERE (orderid = ? AND labelid = ?)');
test.deepEqual(data, [123, 3]);
cb();
}
])
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment