Created
March 30, 2020 16:31
-
-
Save IvanTorresEdge/b3d711ddc73dab8dd0e5e552a9adbf62 to your computer and use it in GitHub Desktop.
Testing Responsive Layouts with Jest+React Testing Library
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
import matchMediaPolyfill from 'mq-polyfill'; | |
matchMediaPolyfill(window); | |
window.matchMedia('(max-width: 640px)'); | |
window.matchMedia('(max-width: 768px)'); | |
window.matchMedia('(max-width: 1024px)'); | |
window.matchMedia('(max-width: 1280px)'); | |
window.resizeTo = function resizeTo(width, height): void { | |
Object.assign(this, { | |
innerWidth: width, | |
innerHeight: height, | |
outerWidth: width, | |
outerHeight: height, | |
}).dispatchEvent(new this.Event('resize')); | |
}; | |
test('whatever you're testing', () => { | |
window.resizeTo(768, 1280); | |
// ...expect yadah yadah | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment