I'm attempting to create a Jest test that tests the implementation of a class that instantiates a LightningChartJS ChartXY.
The following error is thrown during the instantiation of the Chart:
EngineError: Null pointer in i
...
at new i (../../node_modules/@arction/lcjs/dist/lcjs.js:1:8948)
at Ot (../../node_modules/@arction/lcjs/dist/lcjs.js:1:20740)
at new i (../../node_modules/@arction/lcjs/dist/lcjs.js:1:458125)
at ../../node_modules/@arction/lcjs/dist/lcjs.js:47:49973
at Object.ChartXY (../../node_modules/@arction/lcjs/dist/lcjs.js:47:211838)
at new LightningPlot (src/app/lightningChart.ts:70:8)
This GH issue hints at the source of the problem: LightningChartJS does not find the respective DOM node to insert into.
What I've tried so far:
- Import jest-canvas-mock into the setup (necessary to enable canvas in JSDom and avoid this issue)
- using a JSDom import during setup to mock the DOM (based on this SO answer)
- Using the Jest testEnvironment
jest-environment-jsdom
configuration
The DOM mock was tested in several ways:
- using createElement()
- setting innerHTML of the body