chartjs / chartjs/Chart.js

[jest] No known conditions for "./auto" entry in "chart.js" package

Open
#10,887 16 comments 0 reactions 0 assignees View on GitHub
type: bug
Dominant language
JavaScript
Stars
67.7k
Forks
11.9k
Avg merge
7h 39m
Merged PRs (30d)
5

Description

### Expected behavior

All the unit tests using chart.js must run without any error.

### Current behavior

With the new version(v4.0.1) of chart.js update the unit tests are failing.

I am currently using yarn 2 as package manager.

please find the below error:

FAIL src/components/apps/analytics/SampleChart.test.js

● Test suite failed to run

No known conditions for "./auto" entry in "chart.js" package

1 | import React from 'react';

> 2 | import Chart from 'chart.js/auto'; // eslint-disable-line no-unused-vars

| ^

3 | import { Bar } from 'react-chartjs-2';

4 |

5 | const chartData = {

at bail (.yarn/cache/resolve.exports-npm-1.1.0-81756e03ba-52865af8ed.zip/node_modules/resolve.exports/dist/index.js:32:8)

at resolve (.yarn/cache/resolve.exports-npm-1.1.0-81756e03ba-52865af8ed.zip/node_modules/resolve.exports/dist/index.js:89:32)

at Object. (src/components/apps/analytics/SampleChart.js:2:1)

at Object. (src/components/apps/analytics/SampleChart.test.js:3:1)

Test Suites: 1 failed, 1 total

Tests: 0 total

Snapshots: 0 total

Time: 6.932 s

steps to reproduce:

Samplechart,js

import React from 'react';

import Chart from 'chart.js/auto'; // eslint-disable-line no-unused-vars

import { Bar } from 'react-chartjs-2';

const chartData = {

labels: ['05-Sep-21', '12-Sep-21', '19-Sep-21', '26-Sep-21', '03-Oct-21', '10-Oct-21'],

datasets: [

{

barPercentage: 1,

label: 'Top 10 Avg [ALL]',

backgroundColor: ['#9AC355'],

data: [1, 2, 3, 4, 5, 0],

},

],

};

const SampleChart = () => {

return (

);

};

export default SampleChart;

Samplechart.test.js

import React from 'react';

import { customRender, screen, waitFor } from '../../../util/test-utils';

import SampleChart from './SampleChart';

describe('Sample test for chart js', () => {

it('renders without error', () => {

customRender();

});

});

I tried to mock the chart .js by default import . I am facing the same error.

● Test suite failed to run

No known conditions for "." entry in "chart.js" package

28 | }),

29 | }));

> 30 | jest.mock('chart.js', () => ({

| ^

31 | default: jest.fn(() => {}),

32 | }));

33 |

at bail (.yarn/cache/resolve.exports-npm-1.1.0-81756e03ba-52865af8ed.zip/node_modules/resolve.exports/dist/index.js:32:8)

at resolve (.yarn/cache/resolve.exports-npm-1.1.0-81756e03ba-52865af8ed.zip/node_modules/resolve.exports/dist/index.js:89:32)

at Object.mock (src/components/apps/analytics/AnalyticsApp.test.js:30:6)

Test Suites: 1 failed, 1 total

Tests: 0 total

Snapshots: 0 total

Time: 3.288 s

Request to please solve the issue.

### Reproducible sample

-

### Optional extra steps/info to reproduce

_No response_

### Possible solution

_No response_

### Context

_No response_

### chart.js version

v4.0.1

### Browser name and version

_No response_

### Link to your project

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.