Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hi guys, Was trying to create test code for the amchart, using jest but faced some issue. #1223

Closed
brijesh-imemori opened this issue Dec 11, 2023 · 11 comments

Comments

@brijesh-imemori
Copy link

brijesh-imemori commented Dec 11, 2023

import * as am5 from "@amcharts/amcharts5";
import * as am5xy from "@amcharts/amcharts5/xy";

export function makeChart() {
const root = am5.Root.new("chartdiv");

const chart = root.container.children.push(
am5xy.XYChart.new(root, {
panX: false,
panY: false,
wheelX: "panX",
wheelY: "zoomX",
})
);

return { root, chart };
}
import { makeChart } from "layouts/dashboards/imemori/ProjectedAndOpps/ProjectRev/amcharttesting";

beforeEach(() => {
// Create

which is needed by the chart
const div = document.createElement("div");
div.id = "chartdiv";
document.body.appendChild(div);
});
test("chart exists", () => {
const { root, chart } = makeChart();
(url)
// Test chart
expect(root).toBeDefined();
expect(chart).toBeDefined();
expect(chart.get("wheelX")).toBe("panX");
});

Error:
image

I have been working on the test code for AmCharts, and I've encountered an issue. Despite trying various solutions, I haven't been able to find a resolution for this particular problem, So guys please help me out to resolve this issue.

@martynasma
Copy link
Collaborator

Have you reviewed our Jest tutorial?
https://www.amcharts.com/docs/v5/getting-started/integrations/jest/

@brijesh-imemori
Copy link
Author

Hi @martynasma apologies for the late reply, regarding the issue, yeah I have done the same thing that you guys mentioned in the documentation.

babel.config.js:

image

jest.config.js:

image

package.json (devDependencies):

image

package.json (dependencies):

image

as you can see in the above images, please let me know what else I need to do, to complete my test code for the component.

@Pauan
Copy link
Collaborator

Pauan commented Dec 12, 2023

Are you sure that you have canvas setup properly? Were there any warnings or errors when you installed canvas?

Also, you need to remove the chartdiv element, otherwise it'll create duplicates:

afterEach(() => {
    document.body.removeChild(document.getElementById("chartdiv"));
});

@brijesh-imemori
Copy link
Author

Hi @Pauan sorry for the late reply, yeah I am using it correctly, but can you show me for example how you have created the test code for the amCharts? That will be great help.

@Pauan
Copy link
Collaborator

Pauan commented Dec 15, 2023

The afterEach is based on your code which you provided earlier.

Our docs show how to set up everything correctly (including the tests), and we have a working example.

Copy link

This issue is stale because it has been open 30 days with no activity. It will be closed in 5 days unless a new comment is added.

@stanley985
Copy link

@brijesh-imemori did your issue resolved? I've met the same issue as you.

@brijesh-imemori
Copy link
Author

Hi @stanley985 ,
https://stackblitz.com/edit/node-mm8hqa?file=src%2FApp.js This will help you with what to do.

and also create jest.config.js

module.exports = {
// Jest configuration options go here
verbose: true,
collectCoverage: true,
moduleDirectories: ["node_modules", "src"],
// to ignore amChart
transformIgnorePatterns: ["/node_modules/(?!@amcharts|d3-|d3-array|internmap)"],
testEnvironment: "jsdom",
moduleNameMapper: {
"\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
"/src/mocks/fileMock.js",
"\.(css|less)$": "/src/mocks/styleMock.js",
},
// ...other options
setupFilesAfterEnv: ["/src/jest-setup.ts"],
};

and add the above code to that. also, we have made some changes in package.json

"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test -- --config=jest.config.js --collectCoverage",
"clear_jest": "jest --clearCache",
"eject": "react-scripts eject"
},

just look into it if this helps.

@stanley985
Copy link

Hi @stanley985 , https://stackblitz.com/edit/node-mm8hqa?file=src%2FApp.js This will help you with what to do.

and also create jest.config.js

module.exports = { // Jest configuration options go here verbose: true, collectCoverage: true, moduleDirectories: ["node_modules", "src"], // to ignore amChart transformIgnorePatterns: ["/node_modules/(?!@amcharts|d3-|d3-array|internmap)"], testEnvironment: "jsdom", moduleNameMapper: { ".(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "/src/mocks/fileMock.js", ".(css|less)$": "/src/mocks/styleMock.js", }, // ...other options setupFilesAfterEnv: ["/src/jest-setup.ts"], };

and add the above code to that. also, we have made some changes in package.json

"scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test -- --config=jest.config.js --collectCoverage", "clear_jest": "jest --clearCache", "eject": "react-scripts eject" },

just look into it if this helps.

I will have a look and test if this work for me. whether success or not I will inform you. thanks a lot for this.

@stanley985
Copy link

Hi @stanley985 , https://stackblitz.com/edit/node-mm8hqa?file=src%2FApp.js This will help you with what to do.
and also create jest.config.js
module.exports = { // Jest configuration options go here verbose: true, collectCoverage: true, moduleDirectories: ["node_modules", "src"], // to ignore amChart transformIgnorePatterns: ["/node_modules/(?!@amcharts|d3-|d3-array|internmap)"], testEnvironment: "jsdom", moduleNameMapper: { ".(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "/src/mocks/fileMock.js", ".(css|less)$": "/src/mocks/styleMock.js", }, // ...other options setupFilesAfterEnv: ["/src/jest-setup.ts"], };
and add the above code to that. also, we have made some changes in package.json
"scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test -- --config=jest.config.js --collectCoverage", "clear_jest": "jest --clearCache", "eject": "react-scripts eject" },
just look into it if this helps.

I will have a look and test if this work for me. whether success or not I will inform you. thanks a lot for this.

Does your package.json config same as officer doc? I used Angular not React

@brijesh-imemori
Copy link
Author

We are using React ts, it worked for us.
Don't know how to implement it in angular.

david-mears-2 added a commit to jameel-institute/daedalus-web-app that referenced this issue Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants