Closed jebbard closed 1 year ago
Hi Jans, this is expected. getBBox is the Web API this package uses to compute the final bounding box of each rating item.
Such Web API isn't supported in Node environments like jest-dom or happy-dom and needs to be stubbed unless you prefer to run the tests in a real browser (using Cypress, Playwright, etc.).
I've used react-testing-library as well, and that's the mock implementation:
beforeEach(() => {
window.SVGElement.prototype.getBBox = () => ({
x: 0,
y: 0,
width: 0,
height: 0,
})
})
afterEach(() => {
delete window.SVGElement.prototype.getBBox
})
https://github.com/smastrom/react-rating/blob/main/tests/dom/setupTests.ts
Also, the data-test-id
you added to the Rating component won't be added to the root element so you might want to select it using this class: .rr--group
.
I currently cannot use the Rating component with the react testing library. Here is a minimal example:
If I run it with
yarn test Rating.test.tsx
, I get following error:What do I need to do to use it with react testing library?