Skip to content

Commit

Permalink
test(packages/ui): test when alt prop is falsy in the image
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlemoos committed Mar 18, 2024
1 parent 5ff89d0 commit aa2da2a
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions packages/ui/src/image/image.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@ vi.mock('next/image', () => ({

describe('given that an asset is loaded onto the page', () => {
describe('when the image is rendered', () => {
describe('and the alt text is NOT provided', () => {
describe('and the alt text is falsy', () => {
test('then log an error to the console', () => {
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {})
const imageSource = '/path/to/image.jpg'

// @ts-expect-error NOTE: We are testing the error message
render(<Image src={imageSource} width={18} height={18} />)
render(<Image src={imageSource} alt="" width={18} height={18} />)

expect(consoleError).toHaveBeenCalledWith(
`The source of the image must have an alt attribute. Please review the <Image src=\"${imageSource}\" alt=\"\" /> and provide an alt attribute for the image.`,
)

consoleError.mockRestore()
})
})
Expand Down

0 comments on commit aa2da2a

Please sign in to comment.