mercredi 28 juin 2017

Handling global imports with Jest, React, and Webpack

I recently started working on an already mature project where I am integrating the Jest testing framework. The project uses React with Webpack. In the webpack config, the team is using webpack.ProvidePlugin to provide React, lodash, and classnames (not what I would have done, but whatever).

The problem I'm running into, is that most of the React classes at the top of the file contain something like React.Component, which works fine because of the webpack base config. However, when I run the corresponding test file, I just get React is not defined unless I explicitly require React.

There is a webpack.test.config file that requires the base webpack config, but nevertheless I can't seem to get it so that I can run the tests without explicitly including import React from 'react' at the top of every file. I don't want to have to go manually import React in every file, anyone have any suggestions of what to do?

Aucun commentaire:

Enregistrer un commentaire