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

Fix toHaveStyleRule support classes with displayName prefix #302

Merged
merged 3 commits into from Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/toHaveStyleRule.js
Expand Up @@ -68,7 +68,7 @@ const getModifiedClassName = (className, staticClassName, modifier = "") => {
};

const hasClassNames = (classNames, selectors, options) => {
const staticClassNames = classNames.filter(x => x.startsWith("sc-"));
const staticClassNames = classNames.filter(x => /^(\w+(-|_))?sc-/.test(x));

return classNames.some(className =>
staticClassNames.some(staticClassName =>
Expand Down
11 changes: 11 additions & 0 deletions test/toHaveStyleRule.spec.js
Expand Up @@ -491,3 +491,14 @@ it("empty children", () => {

toHaveStyleRule(<Wrapper />, "background", "papayawhip");
});

it("custom display name prefix", () => {
const Text = styled.span.withConfig({ displayName: 'Text__sc' })`
color: red;
`;
const Comp = styled(Text).withConfig({ displayName: 'Comp__Sub-sc' })`
background: papayawhip;
`;
toHaveStyleRule(<Comp />, "background", "papayawhip");
toHaveStyleRule(<Comp />, "color", "red");
});