Skip to content

Commit 50682b5

Browse files
committed
tests: update tests
1 parent 8848fa0 commit 50682b5

File tree

3 files changed

+4
-105
lines changed

3 files changed

+4
-105
lines changed

jest.config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
'use strict'
99

1010
module.exports = {
11-
moduleNameMapper: {
12-
'\\.(css|scss)$': '<rootDir>/packages/coreui-icons-react/test/styleMock.js',
13-
},
1411
preset: 'ts-jest',
1512
setupFiles: ['jest-canvas-mock'],
1613
testEnvironment: 'jsdom',

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
"src/"
3636
],
3737
"scripts": {
38-
"build": "rollup -c --bundleConfigAsCjs"
38+
"build": "rollup -c --bundleConfigAsCjs",
39+
"test": "jest --coverage",
40+
"test:update": "jest --coverage --updateSnapshot"
3941
},
4042
"dependencies": {
4143
"@coreui/chartjs": "^3.1.1",
@@ -52,6 +54,7 @@
5254
"@types/react-dom": "^18.0.11",
5355
"classnames": "^2.3.2",
5456
"jest": "^29.5.0",
57+
"jest-canvas-mock": "^2.4.0",
5558
"jest-environment-jsdom": "^29.5.0",
5659
"lodash": "^4.17.21",
5760
"prop-types": "^15.8.1",

src/__tests__/CChart.spec.tsx

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,6 @@ describe('<CChart />', () => {
7272
expect(chart.config.type).toEqual('bar')
7373
})
7474

75-
it('should pass props onto chart if data is fn', () => {
76-
const dataFn = jest.fn((c) => (c ? data : { datasets: [] }))
77-
78-
render(<CChart data={dataFn} options={options} type="bar" ref={ref} wrapper={false} />)
79-
80-
expect(chart.config.data).toMatchObject(data)
81-
expect(chart.config.options).toMatchObject(options)
82-
expect(chart.config.type).toEqual('bar')
83-
84-
expect(dataFn).toHaveBeenCalledTimes(1)
85-
expect(dataFn).toHaveBeenCalledWith(expect.any(HTMLCanvasElement))
86-
expect(update).toHaveBeenCalledTimes(1)
87-
})
88-
8975
it('should pass new data on data change', () => {
9076
const newData = {
9177
labels: ['red', 'blue'],
@@ -129,76 +115,6 @@ describe('<CChart />', () => {
129115
expect(chart.id).toEqual(id)
130116
})
131117

132-
// it('should properly maintain order with new data', () => {
133-
// const oldData = {
134-
// labels: ['red', 'blue'],
135-
// datasets: [
136-
// { label: 'new-colors', data: [1, 2] },
137-
// { label: 'colors', data: [3, 2] },
138-
// ],
139-
// }
140-
141-
// const newData = {
142-
// labels: ['red', 'blue'],
143-
// datasets: [
144-
// { label: 'colors', data: [3, 2] },
145-
// { label: 'new-colors', data: [1, 2] },
146-
// ],
147-
// }
148-
149-
// const { rerender } = render(
150-
// <CChart data={oldData} options={options} type="bar" ref={ref} wrapper={false} />,
151-
// )
152-
153-
// const meta = Object.assign({}, chart._metasets)
154-
155-
// const id = chart.id
156-
157-
// rerender(<CChart data={newData} options={options} type="bar" ref={ref} wrapper={false} />)
158-
159-
// expect(chart.config.data).toMatchObject(newData)
160-
// expect(meta[0]).toBe(chart._metasets[1])
161-
// expect(meta[1]).toBe(chart._metasets[0])
162-
// expect(update).toHaveBeenCalled()
163-
// expect(chart.id).toEqual(id)
164-
// })
165-
166-
// it('should properly update when original data did not exist', () => {
167-
// const oldData = {
168-
// labels: ['red', 'blue'],
169-
// datasets: [
170-
// { label: 'new-colors', data: [1, 6] },
171-
// { label: 'colors', data: [3, 2] },
172-
// ],
173-
// }
174-
175-
// const newData = {
176-
// labels: ['red', 'blue'],
177-
// datasets: [
178-
// { label: 'colors', data: [4, 5] },
179-
// { label: 'new-colors', data: [1, 2] },
180-
// ],
181-
// }
182-
183-
// const { rerender } = render(
184-
// <CChart data={oldData} options={options} type="bar" ref={ref} wrapper={false} />,
185-
// )
186-
187-
// // even when we feed the data as undefined, the constructor will
188-
// // force it to []. Here we force it back
189-
// chart.config.data.datasets[0].data = undefined
190-
// const meta = Object.assign({}, chart._metasets)
191-
192-
// const id = chart.id
193-
194-
// rerender(<CChart data={newData} options={options} type="bar" ref={ref} wrapper={false} />)
195-
196-
// expect(chart.config.data).toMatchObject(newData)
197-
// expect(meta[0]).toBe(chart._metasets[1])
198-
// expect(update).toHaveBeenCalled()
199-
// expect(chart.id).toEqual(id)
200-
// })
201-
202118
it('should properly update when incoming data does not exist', () => {
203119
const oldData = {
204120
labels: ['red', 'blue'],
@@ -348,23 +264,6 @@ describe('<CChart />', () => {
348264
expect(getElementsAtEvent).toHaveBeenCalled()
349265
})
350266

351-
// it('should show fallback content if given', () => {
352-
// const fallback = <p data-testid="fallbackContent">Fallback content</p>
353-
// const { getByTestId } = render(
354-
// <CChart
355-
// data={data}
356-
// options={options}
357-
// className="chart-example"
358-
// type="bar"
359-
// ref={ref}
360-
// fallbackContent={fallback}
361-
// />,
362-
// )
363-
364-
// expect(chart).toBeTruthy()
365-
// expect(chart.canvas).toContainElement(getByTestId('fallbackContent'))
366-
// })
367-
368267
it('should pass through aria labels to the canvas element', () => {
369268
const ariaLabel = 'ARIA LABEL'
370269
render(<CChart data={data} options={options} type="bar" ref={ref} aria-label={ariaLabel} />)

0 commit comments

Comments
 (0)