简体   繁体   English

无法模拟用于react-inlinesvg Jest测试的图标

[英]Cannot mock icons for react-inlinesvg Jest testing

Getting the stacktrace 获取堆栈跟踪

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)

When rendering SVG icons. 渲染SVG图标时。 My mock is configured in package.json as "\\\\.(svg|ttf|jpg)$": "<rootDir>/src/__mocks__/fileMock.js", and fileMock.js`'s contents are: 我的模拟在package.json中配置为"\\\\.(svg|ttf|jpg)$": "<rootDir>/src/__mocks__/fileMock.js", and fileMock.js的内容是:

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

` `

test-file-mock is the string not matching the desired pattern. test-file-mock是与所需模式不匹配的字符串。 Replace it with an empty string, ie: 将其替换为空字符串,即:

module.exports = '';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM