vendredi 5 juillet 2019

React-testing-library render function throws syntax error

I am trying to start using react-testing-library on my project. Problem is, I can't setup everything properly.

Steps I made:

  1. I installed @testing-library/react and jest-dom as documentation suggests.
  2. I setup jest.config.js:

    module.exports = {
        setupFilesAfterEnv: [
            '@testing-library/react/cleanup-after-each',
        ],
    };
    
    
  3. I wrote basic test:

    import React from 'react';
    import App from '../App';
    import {render } from "@testing-library/react";
    
    it('renders without crashing', () => {
        const {asFragment} = render(<App/>);
        expect(asFragment).toMatchSnapshot();
    });
    
    

Error I get:

  4 |
  5 | it('renders without crashing', () => {
> 6 |     const {asFragment} = render(<App/>);
    |                                 ^
  7 |     expect(asFragment).toMatchSnapshot();
  8 | });
  9 |

My packages versions from package.json file:

"@testing-library/react": "^8.0.4",
"jest-dom": "^3.5.0",
"jest": "^24.8.0",
"react": "^16.6.3",
"react-dom": "^16.6.3",

I've tried several things like cleanuping locally not from jest.config.js file to make it work, but nothing seems to work.

Aucun commentaire:

Enregistrer un commentaire