Created
October 9, 2018 16:04
-
-
Save quetzaluz/07fa3b453edac9f22ae16c5bd4e82861 to your computer and use it in GitHub Desktop.
Method for quickly generating jest spy boilerplate given a list of stringified module dot class
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
function generateSpyFromMethod (mthdList) { | |
const top = [] | |
const bottom = [] | |
mthdList.forEach(function (mthd) { | |
const spl = mthd.split('.') | |
let first = spl[0] | |
let last = spl[1] | |
first = first[0].toLowerCase() + first.slice(1) | |
last = last[0].toUpperCase() + last.slice(1) | |
const spyVar = `${first}${last}Spy` | |
top.push(`let ${spyVar}`) | |
bottom.push(` | |
${spyVar} = spyOn( | |
${spl[0]}, | |
'${spl[1]}' | |
) | |
`) | |
}) | |
return (` | |
${top.join('\n')} | |
beforeEach(() => { | |
${bottom.join('\n')} | |
}) | |
`) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment