Skip to content

Instantly share code, notes, and snippets.

@Farenheith
Created February 29, 2020 06:52
Show Gist options
  • Save Farenheith/357be7184551e7ca67a6b38954009f36 to your computer and use it in GitHub Desktop.
Save Farenheith/357be7184551e7ca67a6b38954009f36 to your computer and use it in GitHub Desktop.
import { expect } from 'chai';
import { stub, match } from 'sinon';
import { anonymousExample } from '../src/anonymous-example';
describe('anonymousExample()', () => {
beforeEach(() => {
stub(console, 'log');
});
it('should log first v when v is 1', () => {
const callbacker = stub().callsFake(cb => cb(1));
const result = anonymousExample(callbacker);
expect(callbacker).to.have.been.calledOnceWithExactly(match.func);
expect(console.log).to.have.been.calledOnceWithExactly('first v!');
});
it('should log another v when v is not 1', () => {
const callbacker = stub().callsFake(cb => cb('anything else'));
const result = anonymousExample(callbacker);
expect(callbacker).to.have.been.calledOnceWithExactly(match.func);
expect(console.log).to.have.been.calledOnceWithExactly('another v!');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment