How to render PhotoAlbum in jest tests #113
Answered
by
igordanchenko
igordanchenko
asked this question in
Q&A
-
PhotoAlbum doesn't render any photos in jest tests. |
Beta Was this translation helpful? Give feedback.
Answered by
igordanchenko
May 15, 2023
Replies: 1 comment
-
This is happening because jsdom sets all elements' beforeAll(() => {
jest
.spyOn(HTMLElement.prototype, "clientWidth", "get")
.mockImplementation(function () {
return (this.className || "").split(" ").includes("react-photo-album")
? 800
: 0;
});
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
igordanchenko
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is happening because jsdom sets all elements'
clientWidth
to 0. You can overcome this limitation with the following mock.