Skip to content

How to render PhotoAlbum in jest tests #113

Discussion options

You must be logged in to vote

This is happening because jsdom sets all elements' clientWidth to 0. You can overcome this limitation with the following mock.

beforeAll(() => {
  jest
    .spyOn(HTMLElement.prototype, "clientWidth", "get")
    .mockImplementation(function () {
      return (this.className || "").split(" ").includes("react-photo-album")
        ? 800
        : 0;
    });
});

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by igordanchenko
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant