Jest unit testing
arbKow opened this issue · comments
Hi!.
Not sure if it's related with package itself or my jest config but it's worth to ask.
I'm having a classic error when I'm importing .svg
file and putting it to ReactSvg
component.
Error: Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
SyntaxError: Unexpected token '<'
> 1 | import IconTrash from './IconTrash.svg'
| ^
2 | import IconSearch from './IconSearch.svg'
3 | import IconStudies from './IconStudies.svg'
4 | import IconLogout from './IconLogout.svg'
jest.config.js:
export default {
displayName: 'fe-components',
preset: '../../jest.preset.js',
transform: {
'^.+\\.(js|jsx|ts|tsx)$': 'babel-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/libs/fe-components',
};
Looks like jest
don't understand svgs
. Does anyone had that issue and coped with it?
Hi @arbKow.
This library makes AJAX requests for SVGs under the hood, so you'll have to handle those requests somehow in your tests. For example, this library uses nock
to mock the requests.
Closing due to inactivity.