Skip to content

Commit caae611

Browse files
committed
Merge branch 'docs/starlight' into build/esm-only
2 parents a917263 + a3a1391 commit caae611

1 file changed

Lines changed: 63 additions & 7 deletions

File tree

‎src/typedCharts.spec.tsx‎

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import {
1111
} from '@testing-library/react'
1212
import {
1313
Chart as ChartJS,
14-
LinearScale
14+
ArcElement,
15+
DoughnutController,
16+
LinearScale,
17+
PointElement,
18+
ScatterController
1519
} from 'chart.js'
1620
import type { Plugin } from 'chart.js'
1721
import type { ChartJSOrUndefined } from './types.js'
@@ -21,7 +25,7 @@ import {
2125
} from './typedCharts.js'
2226

2327
// The components register their controllers themselves
24-
ChartJS.register(LinearScale)
28+
ChartJS.register(ArcElement, LinearScale, PointElement)
2529

2630
describe('typedCharts', () => {
2731
const data = {
@@ -33,21 +37,49 @@ describe('typedCharts', () => {
3337
})
3438

3539
describe('Scatter', () => {
40+
const scatterData = {
41+
datasets: [
42+
{
43+
data: [
44+
{
45+
x: 1,
46+
y: 1
47+
}
48+
]
49+
}
50+
]
51+
}
52+
3653
it('should render a scatter chart', () => {
3754
const ref = createRef<ChartJSOrUndefined<'scatter'>>()
3855

3956
render(
4057
<Scatter
4158
ref={ref}
42-
data={data}
59+
data={scatterData}
60+
options={{
61+
responsive: false
62+
}}
63+
/>
64+
)
65+
66+
expect(ref.current?.getDatasetMeta(0).controller).toBeInstanceOf(ScatterController)
67+
})
68+
69+
it('should pass the chart instance to a ref', () => {
70+
const ref = createRef<ChartJSOrUndefined<'scatter'>>()
71+
72+
render(
73+
<Scatter
74+
ref={ref}
75+
data={scatterData}
4376
options={{
4477
responsive: false
4578
}}
4679
/>
4780
)
4881

4982
expect(ref.current).toBeInstanceOf(ChartJS)
50-
expect(ref.current?.config).toHaveProperty('type', 'scatter')
5183
})
5284

5385
it('should accept plugins of its chart type', () => {
@@ -91,21 +123,45 @@ describe('typedCharts', () => {
91123
})
92124

93125
describe('Doughnut', () => {
126+
const doughnutData = {
127+
datasets: [
128+
{
129+
data: [1]
130+
}
131+
]
132+
}
133+
94134
it('should render a doughnut chart', () => {
95135
const ref = createRef<ChartJSOrUndefined<'doughnut'>>()
96136

97137
render(
98138
<Doughnut
99139
ref={ref}
100-
data={data}
140+
data={doughnutData}
101141
options={{
102142
responsive: false
103143
}}
104144
/>
105145
)
106146

107-
expect(ref.current).toBeInstanceOf(ChartJS)
108-
expect(ref.current?.config).toHaveProperty('type', 'doughnut')
147+
expect(ref.current?.getDatasetMeta(0).controller).toBeInstanceOf(DoughnutController)
148+
})
149+
150+
it('should pass options to the chart', () => {
151+
const ref = createRef<ChartJSOrUndefined<'doughnut'>>()
152+
153+
render(
154+
<Doughnut
155+
ref={ref}
156+
data={doughnutData}
157+
options={{
158+
responsive: false,
159+
cutout: '75%'
160+
}}
161+
/>
162+
)
163+
164+
expect(ref.current?.options).toHaveProperty('cutout', '75%')
109165
})
110166

111167
it('should accept options of its chart type', () => {

0 commit comments

Comments
 (0)