-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor utils for window resize tests into module.
Update all tests to use window resize test utils.
- Loading branch information
Showing
7 changed files
with
127 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import 'mock-match-media/jest-setup.cjs'; | ||
import { setMedia } from 'mock-match-media'; | ||
|
||
export const resizeWindow = (width, height = 768) => { | ||
window.innerWidth = width; | ||
window.innerHeight = height; | ||
window.dispatchEvent(new Event('resize')); | ||
setMedia({ | ||
width: `${width}px`, | ||
height: `${height}px`, | ||
}); | ||
}; | ||
|
||
export const testAfterResize = testFunction => { | ||
let animationFrameId; | ||
const assertAfterResize = () => { | ||
testFunction(); | ||
animationFrameId = cancelAnimationFrame(animationFrameId); | ||
}; | ||
animationFrameId = requestAnimationFrame(assertAfterResize); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.