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' ;
25import type { Plugin } from 'chart.js' ;
6+ import type { ChartJSOrUndefined } from './types.js' ;
37import { Doughnut , Scatter } from './typedCharts.js' ;
48
9+ // The components register their controllers themselves
10+ ChartJS . register ( LinearScale ) ;
11+
512describe ( '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