Skip to content

Commit

Permalink
test: add spec
Browse files Browse the repository at this point in the history
  • Loading branch information
bubkoo committed Feb 13, 2025
1 parent 3cd8093 commit 9de3db6
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/spec/on-image-error-handler.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { embedImages } from '../../src/embed-images'

describe('Error Handling in resourceToDataURL', () => {
it('should call the onImageErrorHandler when an error occurs', async () => {
const handlers = {
onError: () => {},
}
spyOn(handlers, 'onError')
const options = { onImageErrorHandler: handlers.onError }
const node = document.createElement('img')
node.src = 'invalid_url'

// Assuming resourceToDataURL is the function being tested
await embedImages(node, options).then(() => {
expect(handlers.onError).toHaveBeenCalled()
})
})

it('should reject with an error if no onImageErrorHandler is provided', async () => {
const options = {}
const node = document.createElement('img')
node.src = 'invalid_url'
await embedImages(node, options).catch((error) => {
expect(() => {
throw error
}).toThrow()
})
})
})

0 comments on commit 9de3db6

Please sign in to comment.