Skip to content

Commit

Permalink
test(image): add coderabbitai suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Arian94 committed Feb 8, 2025
1 parent de08d98 commit ef99401
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/components/image/__tests__/image.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,23 @@ describe("Image", () => {
imageOnload = fn;
this._onload = fn;
},
configurable: true,
});
}

trackImageOnload();
});

afterAll(() => {
// Restore original Image prototype
delete window.Image.prototype._onload;
Object.defineProperty(window.Image.prototype, "onload", {
value: null,
writable: true,
configurable: true,
});
});

it("should render correctly", () => {
const wrapper = render(<Image />);

Expand Down Expand Up @@ -82,11 +93,21 @@ describe("Image", () => {
imageOnerror = fn;
this._onerror = fn;
},
configurable: true,
});
}

trackImageOnerror();

const cleanup = () => {
delete window.Image.prototype._onerror;
Object.defineProperty(window.Image.prototype, "onerror", {
value: null,
writable: true,
configurable: true,
});
};

const onError = jest.fn();
const wrapper = render(
<Image alt="test" fallbackSrc={fallbackSrc} src="wrong-src-address" onError={onError} />,
Expand All @@ -105,6 +126,7 @@ describe("Image", () => {

expect(computedStyle.backgroundImage).toBe(`url(${fallbackSrc})`);
wrapper.unmount();
cleanup();
});

test("renders image if there is no loading or fallback behavior defined", async () => {
Expand Down

0 comments on commit ef99401

Please sign in to comment.