Created
February 20, 2020 00:23
-
-
Save Farenheith/0cb724b78fc2a55937eedf152905107d to your computer and use it in GitHub Desktop.
Example to mock an exported function
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
import * as functionToMock from '../src/other-function'; | |
import { myFunction } from '../src/my-function'; | |
import { stub } from 'sinon'; | |
describe('myFunction()', () => { | |
beforeEach(() => { | |
stub(functionToMock, 'otherFunction').returns('expected result' as any); | |
}); | |
it('should return otherFunction result', () => { | |
const result = myFunction(); | |
expect(functionToMock.otherFunction).to.have.been.calledOnceExactlyWith(123); | |
expect(result).to.be.eq('expected result'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment