Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest unit testing #2035

Closed
arbKow opened this issue Nov 19, 2022 · 3 comments
Closed

Jest unit testing #2035

arbKow opened this issue Nov 19, 2022 · 3 comments

Comments

@arbKow
Copy link

arbKow commented Nov 19, 2022

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?

@tanem
Copy link
Owner

tanem commented Nov 19, 2022

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.

@arbKow
Copy link
Author

arbKow commented Nov 27, 2022

Thanks @tanem :)
I'll try

@tanem
Copy link
Owner

tanem commented Dec 10, 2022

Closing due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants