Fix mediaRegex to allow dot special character #182
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Introduction
The
mediaRegex
is responsible for normalising media queries to be matched against CSS rules.When defining a CSS rule like
@media (min-width: 576px) { ... }
this gets transformed to@media screen and (min-width:576px)
(note the missing space after the colon); these rules can be tested withtoHaveStyleRule
by adding the following key-value to the options object{ media: '(min-width: 576px)' }
and themediaRegex
will transform this at-rule into(min-width:576px)
so that it can match the rule attached to the component.The issue
This doesn't work with decimal values as the regex takes into consideration only letters after the colon.
Decimal values are fully valid and commonly used (even by bootstrap) to avoid things like breakpoints overlap on high-dpi devices and custom zoom.
It might be easy to think that this could be worked around with just removing the space when writing the test condition like so
{ media: '(min-width:575.98px)' }
but first of all the reason for the failure is not obvious at all and secondly this wouldn't work with defined breakpoints where you want your tests to use declared variables rather than manually writing your breakpoints on every test which would force to change all tests whenever these needs to be updated; the following should be achievable:The fix
This PR adds support to decimal values in media queries for
toHaveStyleRule
.An additional unit test has been added to make sure this is taken into consideration for any future update.
Release
As usual I will be very grateful if this could be released ASAP so that I could get my tests to pass again, especially considering that this would be just a patch making it a straightforward release :)