From 2825bd218221ac1560b8530b2798a50378c95504 Mon Sep 17 00:00:00 2001 From: Kamal Osman Date: Fri, 11 Mar 2022 13:54:05 +0000 Subject: [PATCH] Fix issue #403 with snake case filenames --- src/toHaveStyleRule.js | 2 +- test/toHaveStyleRule.spec.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/toHaveStyleRule.js b/src/toHaveStyleRule.js index ba23682..b0d53b6 100644 --- a/src/toHaveStyleRule.js +++ b/src/toHaveStyleRule.js @@ -4,7 +4,7 @@ const shouldDive = (node) => typeof node.dive === 'function' && typeof node.type const isTagWithClassName = (node) => node.exists() && node.prop('className') && typeof node.type() === 'string'; -const isStyledClass = (className) => /^(\w+(-|_))?sc-/.test(className); +const isStyledClass = (className) => /(_|-)+sc-.+|^sc-/.test(className); const hasClassName = (node) => node.length > 0 && diff --git a/test/toHaveStyleRule.spec.js b/test/toHaveStyleRule.spec.js index e5e088c..540f40a 100644 --- a/test/toHaveStyleRule.spec.js +++ b/test/toHaveStyleRule.spec.js @@ -493,3 +493,12 @@ it('custom display name prefix', () => { toHaveStyleRule(, 'background', 'papayawhip'); toHaveStyleRule(, 'color', 'red'); }); + +it("supports snake case display name prefix", () => { + const Text = styled.span` + color: blue; + `; + Text.styledComponentId = `test-case-${Text.styledComponentId}`; + + toHaveStyleRule(, "color", "blue"); +});