"Define is not defined" in Jest when testing es6 module with RequireJS dependency "Define is not defined" in Jest when testing es6 module with RequireJS dependency reactjs reactjs

"Define is not defined" in Jest when testing es6 module with RequireJS dependency


So, RequireJS is not supported by Jest. In my particular case, it was easiest and most appropriate to mock my dependency at the top of MyComponent.test.js:

jest.mock('private-npm-module', () => {  // mock implementation})import MyComponent from '../../components/MyComponent';

This way, when MyComponent is loaded, its dependency is already mocked, so it won't try to load the RequireJS module.

If you really do need to load your RequireJS module for your test, it may be possible to use jest's transform configuration to wrap your implementation in a RequireJS to ES6 converter.