Say I have a simple image based component:
// ./Figure.js
const Figure = ({src}) => (
<img
src={src}
width="100%"
/>
);
I want to test that its width is 100%.
My test:
// ./Figure.test.js
import Figure from './Figure'
import { render, screen } from '@testing-library/react'
describe('Figure', () => {
const setup = () => {
return render(
<Figure
src="https://src.com"
/>
)
}
it('has the right width', () => {
setup()
const image = screen.getByAltText('alt')
expect(image.src).toBe('https://src.com/')
expect(image.width).toBe("100%")
})
})
However, that gives me an error:
● Figure › renders
expect(received).toBe(expected) // Object.is equality
Expected: "100%"
Received: 0
Question: How can I assert the width of an image using React Testing Library without using snapshots?