I'm using jest and enzyme to write tests for my React application. In my App component opencv.js is imported. And the test fails. This is a simplified version of my component
import '../lib/opencv/opencv';
function App () {
console.log('App');
return 2;
}
export { App };
And here is the test
import { App } from './App';
describe('App',() => {
test('App with opencv.js', () => {
expect(App().toBe(2));
});
});
this test fails with the following error
FAIL src/App.test.jsx
● Test suite failed to run
ReferenceError: Module is not defined
28 |
29 | if (typeof Module === 'undefined')
> 30 | Module = {};
| ^
31 | return cv(Module);
32 | }));
33 |
at factory (lib/opencv/opencv.js:30:11)
at Object.<anonymous>._scriptDir (lib/opencv/opencv.js:3:13)
at Object.<anonymous> (lib/opencv/opencv.js:2:2)
at Object.<anonymous> (src/App.jsx:1:1)
at Object.<anonymous> (src/App.test.jsx:1:1)
if I comment this line
import '../lib/opencv/opencv';
the test will pass.
How should I write tests for the component where I import OpenCV?
Versions
react: ^16.8.3,
jest: ^24.9.0,
babel-jest: ^24.9.0,
opencv.js: 3.4.3
Aucun commentaire:
Enregistrer un commentaire