Skip to content

Instantly share code, notes, and snippets.

@skratchdot
Created January 7, 2016 17:58
Show Gist options
  • Save skratchdot/cc48e529029850873f87 to your computer and use it in GitHub Desktop.
Save skratchdot/cc48e529029850873f87 to your computer and use it in GitHub Desktop.
An example of how I was using a sinon stub to mock creating uuids
import uuid from 'node-uuid';
import sinon from 'sinon';
const mockId = '00000000-0000-0000-0000-000000000000';
describe('some test', () => {
it('does something', () => {
// create stub
sinon.stub(uuid, 'v4', function () {
return mockId;
});
expect(someFunction()).to.contain(mockId); // call some function that uses uuid.v4()
uuid.v4.restore(); // this is important when using gulp.watch
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment