Skip to content

Commit 7384525

Browse files
committed
Merge branch 'build/vite' into chore/storybook
2 parents 155ec14 + 7cf547d commit 7384525

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

‎src/typedCharts.spec.tsx‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
1-
import { describe, it, expect } from 'vitest';
1+
import { createRef } from 'react';
2+
import { afterEach, describe, it, expect } from 'vitest';
3+
import { render, cleanup } from '@testing-library/react';
4+
import { Chart as ChartJS, LinearScale } from 'chart.js';
25
import type { Plugin } from 'chart.js';
6+
import type { ChartJSOrUndefined } from './types.js';
37
import { Doughnut, Scatter } from './typedCharts.js';
48

9+
// The components register their controllers themselves
10+
ChartJS.register(LinearScale);
11+
512
describe('typedCharts', () => {
613
const data = {
714
datasets: [],
815
};
916

17+
afterEach(() => {
18+
cleanup();
19+
});
20+
1021
describe('Scatter', () => {
22+
it('should render a scatter chart', () => {
23+
const ref = createRef<ChartJSOrUndefined<'scatter'>>();
24+
25+
render(<Scatter data={data} options={{ responsive: false }} ref={ref} />);
26+
27+
expect(ref.current).toBeInstanceOf(ChartJS);
28+
expect(ref.current?.config).toHaveProperty('type', 'scatter');
29+
});
30+
1131
it('should accept plugins of its chart type', () => {
1232
const element = (
1333
<Scatter data={data} plugins={[] as Plugin<'scatter'>[]} />
@@ -32,6 +52,17 @@ describe('typedCharts', () => {
3252
});
3353

3454
describe('Doughnut', () => {
55+
it('should render a doughnut chart', () => {
56+
const ref = createRef<ChartJSOrUndefined<'doughnut'>>();
57+
58+
render(
59+
<Doughnut data={data} options={{ responsive: false }} ref={ref} />
60+
);
61+
62+
expect(ref.current).toBeInstanceOf(ChartJS);
63+
expect(ref.current?.config).toHaveProperty('type', 'doughnut');
64+
});
65+
3566
it('should accept options of its chart type', () => {
3667
const element = <Doughnut data={data} options={{ cutout: '75%' }} />;
3768

0 commit comments

Comments
 (0)