Skip to content

Instantly share code, notes, and snippets.

@miguelludert
Created October 5, 2017 16:34
Show Gist options
  • Save miguelludert/eefb0099121b49654e3f9a8f253e2f97 to your computer and use it in GitHub Desktop.
Save miguelludert/eefb0099121b49654e3f9a8f253e2f97 to your computer and use it in GitHub Desktop.
Unit testing boilerplate (JS)
const sinon = require('sinon');
const _ = require('lodash');
const chai = require('chai');
const unique = ()=> Math.random().toString();
const quickCommand = (command, obj, ...keys) => {
_.forEach(keys, function(item){
obj[item] = sinon[command](obj, item);
});
};
const quickSpies = _.partial(quickCommand, 'spy');
const quickStubs = _.partial(quickCommand, 'stub');
const quickReset = (...toReset) => {
_.forEach(toReset, (obj) => {
_.forEach(obj, function(item){
if(typeof item.reset === 'function'){
item.reset();
}
});
});
};
describe('logger', () => {
before(() => {
});
after(() => {
quickReset(fs, console);
});
it('should work', () => {
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment