Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use jest to test jsx components?

Tags:

reactjs

jestjs

According to the docs, jest can only be used to test js files. Can we use it to test the jsx? Jsx files? Can we use it to test jsx files? If so, how?

like image 499
Brown Limie Avatar asked Aug 16 '15 17:08

Brown Limie


1 Answers

You can use babel-jest for testing jsx file. Read more at here

To run test for jsx file you need to add more .jsx when unmock or import implement code.

Example:

For Js file: jest.unmock('../jsx/CheckboxWithLabel')

For JSX file: jest.unmock('../jsx/CheckboxWithLabel.jsx')

like image 180
Alex Nguyen Avatar answered Sep 22 '22 08:09

Alex Nguyen