Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add jsdom tests for mobile/touch screen #57

Merged
merged 1 commit into from
Mar 17, 2022
Merged

Conversation

manoldonev
Copy link
Owner

@manoldonev manoldonev commented Mar 17, 2022

Note that it is not possible to properly test tailwind responsive ui with Jest(jsdom) alone. Generally jsdom neither loads the application css files, nor does it support media queries. We can address the former by manually assembling and injecting the tailwind css styles (see setupTests.ts), however, the latter is a bigger and [currently] unsolvable problem.

Mocking media query support (window.matchMedia) is possible either manually, or via packages like jest-matchmedia-mock but this only patches scenarios where the component under test actually calls window.matchMedia(...) programmatically. In our [tailwind] scenario we are dynamically injecting the css (including the @media statements for sm/md/lg/etc. screen modifiers) but jsdom does not trigger media query computation hence the screen modifiers remain inactive. As tailwind is a mobile-first library this effectively means we are stuck with the mobile view for testing.

@manoldonev manoldonev self-assigned this Mar 17, 2022
@manoldonev manoldonev changed the title chore: add jsdom tests chore: add jsdom tests for mobile/touch screen Mar 17, 2022
@manoldonev manoldonev merged commit b544384 into main Mar 17, 2022
@manoldonev manoldonev deleted the mdonev/msw branch March 17, 2022 18:05
@manoldonev
Copy link
Owner Author

👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant