Created
August 20, 2020 04:44
-
-
Save andrewmclagan/4abb9d6c6cdc2cfbafbd912e6fb0a71f to your computer and use it in GitHub Desktop.
Dependancy mocking in 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
// addNumbers.js | |
import calculator from 'calculator'; | |
export default function addNumbers(a, b) { | |
return calculator.add(a, b); | |
} | |
// addNumbers.spec.js | |
import addNumbers from 'addNumbers.js' | |
import calculator from 'calculator'; | |
jest.mock('calculator'); | |
it('adds two numbers', () => { | |
addNumbers(36, 10); | |
expect(calculator.add.mock).toBeCalledWith(36, 10); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
not sure if the code actually works...