【问题标题】:Cannot mock icons for react-inlinesvg Jest testing无法模拟 react-inlinesvg Jest 测试的图标
【发布时间】:2018-11-21 02:33:23
【问题描述】:

获取堆栈跟踪

SyntaxError: The string did not match the expected pattern.

  at XMLHttpRequest.open (node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js:482:15)
  at http (node_modules/httpplease/lib/index.js:106:9)
  at Function.get (node_modules/httpplease/lib/index.js:139:16)
  at InlineSVG.getFile (node_modules/react-inlinesvg/lib/index.js:151:14)
  at InlineSVG.load (node_modules/react-inlinesvg/lib/index.js:193:19)
  at callCallback (node_modules/react-dom/cjs/react-dom.development.js:10764:12)
  at commitUpdateQueue (node_modules/react-dom/cjs/react-dom.development.js:10797:7)
  at commitLifeCycles (node_modules/react-dom/cjs/react-dom.development.js:14264:11)
  at commitAllLifeCycles (node_modules/react-dom/cjs/react-dom.development.js:15342:7)
  at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:100:14)

渲染 SVG 图标时。我的 mock 在 package.json 中配置为 "\\.(svg|ttf|jpg)$": "<rootDir>/src/__mocks__/fileMock.js", andfileMock.js 的内容是:

module.exports = 'test-file-mock';

`

【问题讨论】:

    标签: javascript reactjs webpack jestjs


    【解决方案1】:

    test-file-mock 是与所需模式不匹配的字符串。将其替换为空字符串,即:

    module.exports = '';
    

    【讨论】:

      猜你喜欢
      • 2021-12-10
      • 2019-04-01
      • 2017-08-17
      • 1970-01-01
      • 2018-05-05
      • 1970-01-01
      • 2021-04-17
      • 2021-12-03
      • 2018-08-29
      相关资源
      最近更新 更多