Created
February 29, 2020 06:52
-
-
Save Farenheith/357be7184551e7ca67a6b38954009f36 to your computer and use it in GitHub Desktop.
This file contains 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
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