Closed marianatuma closed 6 months ago
You can check this out, I had the same problem and this solved it https://github.com/apexcharts/react-apexcharts/issues/425#issuecomment-1734488077
I had the same problem with bar charts I ended up having to disable animations for the tests by setting the property on the global apex object before running the tests.
(global as any).Apex.chart = { animations: { enabled: false, } };
I had the same problem with bar charts I ended up having to disable animations for the tests by setting the property on the global apex object before running the tests.
(global as any).Apex.chart = { animations: { enabled: false, } };
Thanks so much for replying! Just a note, the name Apex
is undefined for me:
TypeError: Cannot set properties of undefined (setting 'chart')
13 |
14 | global.TextEncoder = TextEncoder;
> 15 | (global as any).Apex.chart = { animations: { enabled: false } };
You can check this out, I had the same problem and this solved it apexcharts/react-apexcharts#425 (comment)
This fixed my issue. In case someone else finds this question and is working on angular, I put the following in test-setup.ts
:
jest.mock('ng-apexcharts', () => ({
__esModule: true,
default: () => '<div />',
}));
My bad, I closed this issue too soon.
The solution I thought was working actually threw this error (abridged for readability):
FAIL core apps/core/src/app/components/bar-chart/bar-chart.component.spec.ts
BarChartComponent
✕ should create (187 ms)
● BarChartComponent › should create
TypeError: Cannot read properties of undefined (reading 'ɵcmp')
10 |
11 | beforeEach(async () => {
> 12 | await TestBed.configureTestingModule({
| ^
13 | imports: [BarChartComponent],
14 | }).compileComponents();
15 |
at getComponentDef (../../node_modules/@angular/core/fesm2022/testing.mjs:27091:18)
at isStandaloneComponent (../../node_modules/@angular/core/fesm2022/testing.mjs:27087:17)
at ../../node_modules/@angular/core/fesm2022/testing.mjs:26856:29
at Array.forEach (<anonymous>)
...
My bad, I closed this issue too soon.
The solution I thought was working actually threw this error (abridged for readability):
FAIL core apps/core/src/app/components/bar-chart/bar-chart.component.spec.ts BarChartComponent ✕ should create (187 ms) ● BarChartComponent › should create TypeError: Cannot read properties of undefined (reading 'ɵcmp') 10 | 11 | beforeEach(async () => { > 12 | await TestBed.configureTestingModule({ | ^ 13 | imports: [BarChartComponent], 14 | }).compileComponents(); 15 | at getComponentDef (../../node_modules/@angular/core/fesm2022/testing.mjs:27091:18) at isStandaloneComponent (../../node_modules/@angular/core/fesm2022/testing.mjs:27087:17) at ../../node_modules/@angular/core/fesm2022/testing.mjs:26856:29 at Array.forEach (<anonymous>) ...
Did you find any solution? I faced the same issue.
@egiev Solution is in linked issue, add this to the test
beforeEach(async () => {
Object.defineProperty(window, 'ResizeObserver', {
writable: true,
value:
window.ResizeObserver ||
jest.fn().mockImplementation(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn()
}))
});
Object.defineProperty(global.SVGElement.prototype, 'getScreenCTM', {
writable: true,
value: jest.fn()
});
Object.defineProperty(global.SVGElement.prototype, 'createSVGMatrix', {
writable: true,
value: jest.fn().mockReturnValue({
x: 10,
y: 10,
// eslint-disable-next-line @typescript-eslint/no-empty-function
inverse: () => {},
// eslint-disable-next-line @typescript-eslint/no-empty-function
multiply: () => {}
})
});
});
Thank you!
I have a very simple component that renders a bar chart, and it breaks the unit tests.
The component:
The component's html file:
The
spec.ts
file:And the error (abridged for readability):