diff --git a/__mocks__/imageMock.ts b/__mocks__/assetMock.ts similarity index 67% rename from __mocks__/imageMock.ts rename to __mocks__/assetMock.ts index 69e664597f..5412bc08dc 100644 --- a/__mocks__/imageMock.ts +++ b/__mocks__/assetMock.ts @@ -3,4 +3,4 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ -export default {}; +export default ""; // mostly path to bundled file or data-url (webpack) diff --git a/package.json b/package.json index 76deb82028..1c32eaa61f 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ }, "moduleNameMapper": { "\\.(css|scss)$": "/__mocks__/styleMock.ts", - "\\.(svg)$": "/__mocks__/imageMock.ts" + "\\.(svg|png|jpg|eot|woff2?|ttf)$": "/__mocks__/assetMock.ts" }, "modulePathIgnorePatterns": [ "/dist", diff --git a/src/renderer/components/icon/icon.tsx b/src/renderer/components/icon/icon.tsx index d61d57c663..1335f344ad 100644 --- a/src/renderer/components/icon/icon.tsx +++ b/src/renderer/components/icon/icon.tsx @@ -37,7 +37,7 @@ export class Icon extends React.PureComponent { focusable: true, }; - static isSvg(content: string){ + static isSvg(content: string) { return String(content).includes("svg+xml"); // data-url for raw svg-icon } @@ -63,7 +63,7 @@ export class Icon extends React.PureComponent { switch (evt.nativeEvent.code) { case "Space": - // fallthrough + // fallthrough case "Enter": { this.ref.current?.click(); evt.preventDefault(); @@ -104,10 +104,11 @@ export class Icon extends React.PureComponent { // render as inline svg-icon if (typeof svg === "string") { const dataUrlPrefix = "data:image/svg+xml;base64,"; - const svgIconDataUrl: string = svg.startsWith(dataUrlPrefix) ? svg : require(`./${svg}.svg`); - const svgIconText = decode(svgIconDataUrl.replace(dataUrlPrefix, "")); // get raw xml + const svgIconDataUrl = svg.startsWith(dataUrlPrefix) ? svg : require(`./${svg}.svg`); + const svgIconText = typeof svgIconDataUrl == "string" // decode xml from data-url + ? decode(svgIconDataUrl.replace(dataUrlPrefix, "")) : ""; - iconContent = ; + iconContent = ; } // render as material-icon @@ -135,7 +136,7 @@ export class Icon extends React.PureComponent { } if (href) { - return ; + return ; } return ; diff --git a/types/mocks.d.ts b/types/mocks.d.ts index cc260eacfd..0fbde3b4f9 100644 --- a/types/mocks.d.ts +++ b/types/mocks.d.ts @@ -27,6 +27,7 @@ declare module "*.scss" { } // Declare everything what's bundled as webpack's type="asset/resource" +// Should be mocked for tests support in jestConfig.moduleNameMapper (currently in "/package.json") declare module "*.svg"; declare module "*.jpg"; declare module "*.png";