Created
February 10, 2019 02:49
-
-
Save thisismydesign/db1aca9876cf088692b8b4d7c35bdd7e to your computer and use it in GitHub Desktop.
Mocking per test case with Jest /2
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
export const mockOriginalFunctionality = name => { | |
const actualModule = require.requireActual(name); | |
return { | |
...Object.getOwnPropertyNames(actualModule) | |
.map(functionName => { | |
return { | |
[functionName]: jest.fn().mockImplementation(() => { | |
return actualModule[functionName](); | |
}) | |
}; | |
}) | |
.reduce((accumulator, currentValue) => { | |
return { ...accumulator, ...currentValue }; | |
}) | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment