Skip to content

Instantly share code, notes, and snippets.

@araphiel
Last active July 14, 2023 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save araphiel/20b970b4a41b0fb8ff150124f24233d2 to your computer and use it in GitHub Desktop.
Save araphiel/20b970b4a41b0fb8ff150124f24233d2 to your computer and use it in GitHub Desktop.
simple jest viewport resizer
/** note: jest global.innerWidth defaults to 1024px */
const resizeJestViewport = (breakpoint: Breakpoints) => {
act(() => {
let width;
switch (breakpoint) {
case "desktop":
width = 1200;
break;
case "tablet":
width = 768;
break;
case "mobile":
width = 500;
break;
default:
width = 1024;
}
global.innerWidth = width;
global.dispatchEvent(new Event("resize"));
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment