All files / .config/jest/mocks react-inlinesvg.tsx

62.5% Statements 5/8
100% Branches 0/0
0% Functions 0/1
83.33% Lines 5/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26        1x                   1x   1x   1x           1x  
// Due to the grafana/ui Icon component making fetch requests to
// `/public/img/icon/<icon_name>.svg` we need to mock react-inlinesvg to prevent
// the failed fetch requests from displaying errors in console.
 
import React from 'react';
 
type Callback = (...args: any[]) => void;
 
export interface StorageItem {
  content: string;
  queue: Callback[];
  status: string;
}
 
export const cacheStore: { [key: string]: StorageItem } = Object.create(null);
 
const SVG_FILE_NAME_REGEX = /(.+)\/(.+)\.svg$/;
 
const InlineSVG = ({ src }: { src: string }) => {
  // testId will be the file name without extension (e.g. `public/img/icons/angle-double-down.svg` -> `angle-double-down`)
  const testId = src.replace(SVG_FILE_NAME_REGEX, '$2');
  return <svg xmlns="http://www.w3.org/2000/svg" data-testid={testId} viewBox="0 0 24 24" />;
};
 
export default InlineSVG;