前提:使用 Symbol 方式引用 iconfont 图标。在项目中创建了一个 js 文件,该文件粘贴了 iconfont 生成文件的内容。使用 npm run test:unit 进行单元测试,报以下错误:
TypeError: Cannot read properties of undefined (reading 'getAttribute')
解决办法:
修改存放 iconfont 生成内容的文件
原代码
var t = (t = document.getElementsByTagName("script"))[t.length - 1], a = t.getAttribute("data-injectcss"),t = t.getAttribute("data-disable-injectsvg");
// 修改上方代码,下方代码不变
if (!t) {
var l, e, o, n, c, d = function (t, a) {
......
}
}
修改为
var t = (t = document.getElementsByTagName("script"))[t.length - 1];
if (!t){ return }
var a = t.getAttribute("data-injectcss"),t = t.getAttribute("data-disable-injectsvg");
// 修改上方代码,下方代码不变
if (!t) {
var l, e, o, n, c, d = function (t, a) {
......
}
}