Skip to content

Commit 68acf80

Browse files
Copilotabernier
andcommitted
Remove hard-coded dimension values from canvas tests
Co-authored-by: abernier <[email protected]>
1 parent 061c2a3 commit 68acf80

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

packages/fiber/tests/canvas.test.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import React from 'react'
22
import { render } from '@testing-library/react'
33
import { Canvas, act } from '../src'
44

5+
// Expected dimensions from the mocked react-use-measure hook
6+
const MOCKED_MEASURE_WIDTH = 1280
7+
const MOCKED_MEASURE_HEIGHT = 800
8+
59
describe('web Canvas', () => {
610
it('should correctly mount', async () => {
711
const renderer = await act(async () =>
@@ -101,9 +105,9 @@ describe('web Canvas', () => {
101105
)
102106

103107
const canvas = renderer.container.querySelector('canvas')
104-
// Should use mocked useMeasure dimensions (1280x800)
105-
expect(canvas?.getAttribute('width')).toBe('1280')
106-
expect(canvas?.getAttribute('height')).toBe('800')
108+
// Should use mocked useMeasure dimensions
109+
expect(canvas?.getAttribute('width')).toBe(MOCKED_MEASURE_WIDTH.toString())
110+
expect(canvas?.getAttribute('height')).toBe(MOCKED_MEASURE_HEIGHT.toString())
107111
})
108112

109113
it('should fallback to useMeasure when only height is provided', async () => {
@@ -116,9 +120,9 @@ describe('web Canvas', () => {
116120
)
117121

118122
const canvas = renderer.container.querySelector('canvas')
119-
// Should use mocked useMeasure dimensions (1280x800)
120-
expect(canvas?.getAttribute('width')).toBe('1280')
121-
expect(canvas?.getAttribute('height')).toBe('800')
123+
// Should use mocked useMeasure dimensions
124+
expect(canvas?.getAttribute('width')).toBe(MOCKED_MEASURE_WIDTH.toString())
125+
expect(canvas?.getAttribute('height')).toBe(MOCKED_MEASURE_HEIGHT.toString())
122126
})
123127

124128
it('should fallback to useMeasure when neither width nor height is provided', async () => {
@@ -131,8 +135,8 @@ describe('web Canvas', () => {
131135
)
132136

133137
const canvas = renderer.container.querySelector('canvas')
134-
// Should use mocked useMeasure dimensions (1280x800)
135-
expect(canvas?.getAttribute('width')).toBe('1280')
136-
expect(canvas?.getAttribute('height')).toBe('800')
138+
// Should use mocked useMeasure dimensions
139+
expect(canvas?.getAttribute('width')).toBe(MOCKED_MEASURE_WIDTH.toString())
140+
expect(canvas?.getAttribute('height')).toBe(MOCKED_MEASURE_HEIGHT.toString())
137141
})
138142
})

0 commit comments

Comments
 (0)