I'm integrating the videojs-cmcd
with videojs
in my project, I've followed the steps as provided in this READMe file. Everything works fine when running the app in browser, The cmcd data is being passed in the API as expected. But When I try to write a unit test case for my changes I'm getting the error videojs__default.default.getPlugin is not a function
.
Test suite failed to run
TypeError: videojs__default.default.getPlugin is not a function
1 | import React, { useRef, useEffect, useState } from 'react';
2 | import videojs from 'video.js';
> 3 | import '@montevideo-tech/videojs-cmcd';
| ^
4 | import { IconButton, useMediaQuery } .....
at Object.<anonymous> (../../node_modules/@montevideo-tech/videojs-cmcd/dist/videojs-cmcd.cjs.js:1427:44)
at Object.require (src/video-player/components/video/VideoPlayer.tsx:3:1)
at Object.<anonymous> (src/video-player/components/video/__tests__/VideoPlayer.test.tsx:5:1)
It is a typescript error TypeError
. But I couldn't find @types/..
definition for videojs-cmcd. How can I solve this issue? Is there any work-around for this?
I fixed the issue, but adding the below mock in setupTests.ts file
jest.mock('@montevideo-tech/videojs-cmcd', () => ({
videojs__default: {
default: {
getPlugin: jest.fn(),
}
}
}));
This setupTests.ts is configured in jest.config.json as below
"setupFilesAfterEnv": ["<rootDir>/src/setupTests.ts"]