Skip to content

Commit

Permalink
fix: resolve issue with stylis v4 missing descendent selector spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
quantizor committed Oct 12, 2023
1 parent 756fbb7 commit fe5089b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/toHaveStyleRule.js
Expand Up @@ -47,6 +47,9 @@ const getAtRules = (ast, options) => {
.reduce((acc, rules) => acc.concat(rules), []);
};

/** stylis v4 renders descendant selectors without a trailing space sometimes which trips up detection */
const removeSpaceAfterSelector = input => input.replace(/([>~+])( +)/g, '$1')

const normalizeQuotations = (input) => input.replace(/['"]/g, '"');

const getModifiedClassName = (className, staticClassName, modifier = '') => {
Expand Down Expand Up @@ -75,8 +78,8 @@ const hasClassNames = (classNames, selectors, options) => {

return classNames.some((className) =>
staticClassNames.some((staticClassName) =>
selectors.includes(
normalizeQuotations(getModifiedClassName(className, staticClassName, options.modifier).replace(/['"]/g, '"'))
selectors.map(removeSpaceAfterSelector).includes(
removeSpaceAfterSelector(normalizeQuotations(getModifiedClassName(className, staticClassName, options.modifier).replace(/['"]/g, '"')))
)
)
);
Expand Down

0 comments on commit fe5089b

Please sign in to comment.