Skip to content

Instantly share code, notes, and snippets.

@thisismydesign
Created February 10, 2019 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thisismydesign/db1aca9876cf088692b8b4d7c35bdd7e to your computer and use it in GitHub Desktop.
Save thisismydesign/db1aca9876cf088692b8b4d7c35bdd7e to your computer and use it in GitHub Desktop.
Mocking per test case with Jest /2
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