如何捕获传递给Jest转换器的参数

时间:2017-07-14 14:32:55

标签: javascript handlebars.js jestjs

我有一个Jest变换器拦截手柄文件,编译它们并返回模板函数。

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)。显然,参数会根据此参数更改输出。现在我意识到模拟不应该构建完整的功能......但是有没有办法捕获传递到options的数据并将其传递给template()的字符串化调用?

0 个答案:

没有答案
相关问题