I have a Jest transformer that intercepts handlebar files, compiles them, and returns the template function.
const createCacheKeyFunction = require('fbjs-scripts/jest/createCacheKeyFunction')
const handlebars = require('handlebars')
module.exports = {
process: (src, filename, config, options) => {
const template = handlebars.compile(src)
return `module.exports = (options) => ${JSON.stringify(template())}`
},
getCacheKey: createCacheKeyFunction([__filename])
}
This works superficially and it's "good enough" for my testing but in reality the template() method it returns accepts a parameter (in this case, whatever the calling function passes into options). Obviously the parameter changes the output of based on this parameter. Now I realize that mocks shouldn't build out complete functionality... BUT.. is there a way to capture the data being passed into options and pass it into the stringified call to template()?
Caleb Rogers
Yo, this causing
You must pass a string or Handlebars AST to Handlebars.compile. You passed function ret(context, execOptions) { if (!compiled) { compiled = compileInput(); } return compiled.call(this, context, execOptions); }Error for me, any tips?