Skip to content

Commit b6777f0

Browse files
Copilotabernier
andauthored
Add comprehensive tests for Canvas width and height props (#3553)
* Initial plan * Add comprehensive tests for Canvas width/height props Co-authored-by: abernier <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: abernier <[email protected]>
1 parent 1922504 commit b6777f0

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

packages/fiber/tests/canvas.test.tsx

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,63 @@ describe('web Canvas', () => {
7676

7777
expect(useLayoutEffect).not.toHaveBeenCalled()
7878
})
79+
80+
it('should use manual width and height when provided', async () => {
81+
const renderer = await act(async () =>
82+
render(
83+
<Canvas width={640} height={480}>
84+
<group />
85+
</Canvas>,
86+
),
87+
)
88+
89+
const canvas = renderer.container.querySelector('canvas')
90+
expect(canvas?.getAttribute('width')).toBe('640')
91+
expect(canvas?.getAttribute('height')).toBe('480')
92+
})
93+
94+
it('should fallback to useMeasure when only width is provided', async () => {
95+
const renderer = await act(async () =>
96+
render(
97+
<Canvas width={640}>
98+
<group />
99+
</Canvas>,
100+
),
101+
)
102+
103+
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')
107+
})
108+
109+
it('should fallback to useMeasure when only height is provided', async () => {
110+
const renderer = await act(async () =>
111+
render(
112+
<Canvas height={480}>
113+
<group />
114+
</Canvas>,
115+
),
116+
)
117+
118+
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')
122+
})
123+
124+
it('should fallback to useMeasure when neither width nor height is provided', async () => {
125+
const renderer = await act(async () =>
126+
render(
127+
<Canvas>
128+
<group />
129+
</Canvas>,
130+
),
131+
)
132+
133+
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')
137+
})
79138
})

0 commit comments

Comments
 (0)