Skip to content

Commit 4f772cf

Browse files
author
Camilo QS
authored
Fix toHaveStyleRule support classes with displayName prefix (#302)
* Fix support classes with displayName prefix Closes #290 #294 * simplify regexp on get classname * add unit test for custom prefix/display name
1 parent 6176d93 commit 4f772cf

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/toHaveStyleRule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const getModifiedClassName = (className, staticClassName, modifier = "") => {
7676
};
7777

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

8181
return classNames.some(className =>
8282
staticClassNames.some(staticClassName =>

test/toHaveStyleRule.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,3 +504,14 @@ it("empty children", () => {
504504

505505
toHaveStyleRule(<Wrapper />, "background", "papayawhip");
506506
});
507+
508+
it("custom display name prefix", () => {
509+
const Text = styled.span.withConfig({ displayName: 'Text__sc' })`
510+
color: red;
511+
`;
512+
const Comp = styled(Text).withConfig({ displayName: 'Comp__Sub-sc' })`
513+
background: papayawhip;
514+
`;
515+
toHaveStyleRule(<Comp />, "background", "papayawhip");
516+
toHaveStyleRule(<Comp />, "color", "red");
517+
});

0 commit comments

Comments
 (0)