Javascript 如何捕获传递给Jest转换器的参数
我有一个Jest转换器,它截取handlebar文件,编译它们,然后返回模板函数Javascript 如何捕获传递给Jest转换器的参数,javascript,handlebars.js,jestjs,Javascript,Handlebars.js,Jestjs,我有一个Jest转换器,它截取handlebar文件,编译它们,然后返回模板函数 const createCacheKeyFunction = require('fbjs-scripts/jest/createCacheKeyFunction') const handlebars = require('handlebars') module.exports = { process: (src, filename, config, options) => { const tem
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])
}
这在表面上有效,对于我的测试来说“足够好”,但实际上它返回的template()
方法接受一个参数(在这种情况下,调用函数传递到options
中的任何内容)。显然,该参数会根据此参数更改的输出。现在我意识到mock不应该构建完整的功能。。。但是是否有一种方法可以捕获传递到选项中的数据,并将其传递到对模板()
的字符串化调用中