Open reboottime opened 1 year ago
import React from 'react';
export default 'SvgrURL';
const SvgrMock = React.forwardRef((props, ref) => <span ref={ref} {...props} />);
export const ReactComponent = SvgrMock;
svg
files
moduleNameMapper: {
"\\.svg": "<rootDir>/src/__mocks__/svgrMock.js",
},
Setup Jest
After following CLI guide steps preset by the above command, jest generates a default
jest.config.js
file for us under the root folder.Add basic configurations for our app
Tell jest where to look for files to test (configure jest.config.js)
Also, to transform code, we need babel's help, so let's add
.babelrc.json
setup{ "presets": [ "@babel/preset-env", [ "@babel/preset-react", { "runtime": "automatic" } ] ]
Tell jest how to map alias import in test cases
This step tells jest when reading alias in a source file, where to look for real file.