Skip to content

Commit

Permalink
Improve Jest mock for SVGR components
Browse files Browse the repository at this point in the history
Instead of returning a simple object with the default `ReactComponent`
key the mock now returns an real `<svg>` React component.

GH-76
  • Loading branch information
arcticicestudio committed Dec 15, 2018
1 parent ea3d9fc commit cd9bf4c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module.exports = {
".+\\.(jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
"<rootDir>/test/__mocks__/file.js",
/* Ensure React components loaded from SVG files are mocked correctly. */
".+\\.svg$": "<rootDir>/test/__mocks__/svgr.js"
".+\\.svg$": "<rootDir>/test/__mocks__/svgr.jsx"
},

/*
Expand Down
6 changes: 5 additions & 1 deletion test/__mocks__/svgr.js → test/__mocks__/svgr.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
* @since 0.3.0
*/

module.exports = { ReactComponent: "SvgrComponent" };
import React from "react";

const MockedSvg = props => <svg {...props} />;

module.exports = { ReactComponent: MockedSvg };

0 comments on commit cd9bf4c

Please sign in to comment.