Skip to content

Commit c1411b5

Browse files
committed
2 parents e5e8a52 + b04dff9 commit c1411b5

20 files changed

Lines changed: 348 additions & 355 deletions

File tree

.github/workflows/issue-response.yml

Lines changed: 0 additions & 214 deletions
This file was deleted.

.github/workflows/lockfile-consistency.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

__tests__/components/LazyImage.test.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,28 @@ describe('LazyImage Component', () => {
8989

9090
it('handles load event', async () => {
9191
const handleLoad = jest.fn()
92-
render(<LazyImage {...defaultProps} onLoad={handleLoad} />)
93-
94-
const image = screen.getByAltText('Test image')
95-
96-
// Simulate image load
97-
Object.defineProperty(image, 'complete', { value: true })
98-
image.dispatchEvent(new Event('load'))
99-
100-
await waitFor(() => {
101-
expect(handleLoad).toHaveBeenCalled()
102-
})
92+
const OriginalImage = global.Image
93+
// jsdom does not finish decoding remote URLs; defer onload until after handlers attach (matches browser ordering).
94+
global.Image = class MockImage {
95+
constructor() {
96+
this.onload = null
97+
}
98+
99+
set src(_val) {
100+
queueMicrotask(() => {
101+
if (this.onload) this.onload()
102+
})
103+
}
104+
}
105+
106+
try {
107+
render(<LazyImage {...defaultProps} priority onLoad={handleLoad} />)
108+
await waitFor(() => {
109+
expect(handleLoad).toHaveBeenCalled()
110+
})
111+
} finally {
112+
global.Image = OriginalImage
113+
}
103114
})
104115

105116
it('handles error gracefully', () => {
@@ -122,10 +133,9 @@ describe('LazyImage Component', () => {
122133
})
123134

124135
it('handles missing src gracefully', () => {
125-
render(<LazyImage alt="Test image" />)
126-
127-
const image = screen.getByAltText('Test image')
128-
expect(image).toBeInTheDocument()
136+
const { container } = render(<LazyImage alt="Test image" />)
137+
138+
expect(container.firstChild).toBeNull()
129139
})
130140

131141
it('applies custom styles', () => {

0 commit comments

Comments
 (0)