Skip to content

Commit

Permalink
Remove double nesting for matching compiled css
Browse files Browse the repository at this point in the history
  • Loading branch information
ankeetmaini committed Apr 22, 2020
1 parent 9830560 commit 1d05089
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/jest/src/matchers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ const getMountedProperties = () =>
)
.join(' ');

const containsClassNames = (classNames: string[], css: string) =>
classNames.reduce((accum, className) => (css.includes(`.${className}`) ? true : accum), false);

export function toHaveCompiledCss(
this: jest.MatcherUtils,
element: HTMLElement,
Expand Down Expand Up @@ -56,9 +53,12 @@ export function toHaveCompiledCss(
});
}

if (containsClassNames(classNames, css)) {
foundStyles.push(...stylesToFind.filter(styleToFind => css.includes(styleToFind)));
}
classNames.forEach(c => {
if (css.includes(c)) {
const found = stylesToFind.filter(s => css.includes(s));
foundStyles.push(...found);
}
});
}

const notFoundStyles = stylesToFind.filter(style => !foundStyles.includes(style));
Expand Down

0 comments on commit 1d05089

Please sign in to comment.