Posted 30 November 2021, 1:13 pm EST
Hi,
I have a project built using the Create React App tool and I’m integrating SpreadJS libraries into my app through HTML script tags (not using the NPM packages). This works perfectly.
What I’m having trouble is when trying to create tests of my components that internally create an instance of the SpreadJS Designer component. I’m trying to add tests to my app but having trouble loading the SpreadJS Designer component into the Jest environment.
This is what I’m doing:
- Relevant code in setupTests.js
import 'jest-canvas-mock';
window.GC = require('@grapecity/spread-sheets');
require('../public/Content/js/spreadjs/gc.spread.sheets.designer.resource.en.14.2.0.min.js');
require('../public/Content/js/spreadjs/gc.spread.sheets.designer.all.14.2.0.min.js');
- Relevant parts of package.json
"jest": {
"moduleNameMapper": {
"@grapecity/spread-sheets-charts(.*)": "<rootDir>/public/Content/js/spreadjs/gc.spread.sheets.charts.14.2.0.min.js",
"@grapecity/spread-sheets-languagepackages(.*)": "<rootDir>/public/Content/js/spreadjs/gc.spread.calcengine.languagepackages.14.2.0.min.js",
"@grapecity/spread-sheets-shapes(.*)": "<rootDir>/public/Content/js/spreadjs/gc.spread.sheets.shapes.14.2.0.min.js",
"@grapecity/spread-sheets-print(.*)": "<rootDir>/public/Content/js/spreadjs/gc.spread.sheets.print.14.2.0.min.js",
"@grapecity/spread-sheets-barcode(.*)": "<rootDir>/public/Content/js/spreadjs/gc.spread.sheets.barcode.14.2.0.min.js",
"@grapecity/spread-sheets-pdf(.*)": "<rootDir>/public/Content/js/spreadjs/gc.spread.sheets.pdf.14.2.0.min.js",
"@grapecity/spread-sheets-pivot-addon(.*)": "<rootDir>/public/Content/js/spreadjs/gc.spread.pivot.pivottables.14.2.0.min.js",
"@grapecity/spread-sheets(.*)": "<rootDir>/public/Content/js/spreadjs/gc.spread.sheets.all.14.2.0.min.js",
"@grapecity/spread-excelio(.*)": "<rootDir>/public/Content/js/spreadjs/gc.spread.excelio.14.2.0.min.js"
},
}
This is the error that is printed out when running a test that creates a Designer instance:
Error: Uncaught [TypeError: Cannot read property 'length' of undefined]
at f.updateGroupLayout (
From inspecting the unminified version of file gc.spread.sheets.designer.all.14.2.0.min.js I think the error is thrown somewhere in this piece of code. For some reason this._panelGroupRenders ends up being undefined.
(f.prototype.updateGroupLayout = function (e) {
if (0 < this._panelGroupRenders.length) {
var t = document.body.clientWidth;
this.root && 0 < this.root.clientWidth && (t = this.root.clientWidth),
this._panelGroupRenders[this._activePanelGroupIndex].updateGroupLayout(t, e);
}
}),
Do you know what might be going wrong with my setup?
Thank you,
Andres
