Created
October 5, 2017 16:34
-
-
Save miguelludert/eefb0099121b49654e3f9a8f253e2f97 to your computer and use it in GitHub Desktop.
Unit testing boilerplate (JS)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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