jest-styled-components
Advanced tools
Comparing version 7.0.2 to 7.0.3
@@ -8,2 +8,6 @@ # Changelog | ||
## [7.0.2](https://github.com/styled-components/jest-styled-components/compare/v7.0.1...v7.0.2) - 2020-04-09 | ||
Fix toHaveStyleRule support classes with displayName prefix (#302) thanks @vxcamiloxv | ||
## [7.0.1](https://github.com/styled-components/jest-styled-components/compare/v7.0.0...v7.0.1) - 2020-04-07 | ||
@@ -10,0 +14,0 @@ |
{ | ||
"name": "jest-styled-components", | ||
"version": "7.0.2", | ||
"version": "7.0.3", | ||
"description": "Jest utilities for Styled Components", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
@@ -47,2 +47,3 @@ const css = require('css'); | ||
const filterClassNames = (classNames, hashes) => classNames.filter(className => hashes.includes(className)); | ||
const filterUnreferencedClassNames = (classNames, hashes) => classNames.filter(className => className.startsWith('sc-') && !hashes.includes(className)); | ||
@@ -95,2 +96,6 @@ const includesClassNames = (classNames, selectors) => | ||
const stripUnreferencedClassNames = (result, classNames) => | ||
classNames | ||
.reduce((acc, className) => acc.replace(new RegExp(`${className}\\s?`,'g'), ''), result); | ||
const replaceHashes = (result, hashes) => | ||
@@ -118,3 +123,6 @@ hashes.reduce( | ||
let classNames = [...getClassNames(nodes)]; | ||
let unreferencedClassNames = classNames; | ||
classNames = filterClassNames(classNames, hashes); | ||
unreferencedClassNames = filterUnreferencedClassNames(unreferencedClassNames, hashes); | ||
@@ -126,2 +134,3 @@ const style = getStyle(classNames); | ||
let result = `${style}${style ? '\n\n' : ''}${code}`; | ||
result = stripUnreferencedClassNames(result, unreferencedClassNames); | ||
result = replaceClassNames(result, classNamesToReplace, style); | ||
@@ -128,0 +137,0 @@ result = replaceHashes(result, hashes); |
@@ -8,8 +8,11 @@ const { getCSS, matcherTest, buildReturnMessage } = require("./utils"); | ||
node.exists() && node.prop("className") && typeof node.type() === "string"; | ||
const isStyledClass = className => | ||
/^(\w+(-|_))?sc-/.test(className); | ||
const hasClassName = node => | ||
node.length > 0 | ||
&& typeof node.props === "function" | ||
&& node.props("className") | ||
&& node.props("className").className; | ||
node.length > 0 | ||
&& typeof node.props === "function" | ||
&& node.prop("className") | ||
&& isStyledClass(node.prop("className")) | ||
@@ -23,3 +26,3 @@ const getClassNames = received => { | ||
} else if (hasClassName(received)) { | ||
className = received.props("className").className; | ||
className = received.prop("className"); | ||
} else if (typeof received.exists === "function" && received.exists()) { | ||
@@ -81,3 +84,3 @@ const tree = shouldDive(received) ? received.dive() : received; | ||
const hasClassNames = (classNames, selectors, options) => { | ||
const staticClassNames = classNames.filter(x => /^(\w+(-|_))?sc-/.test(x)); | ||
const staticClassNames = classNames.filter(x => isStyledClass(x)); | ||
@@ -84,0 +87,0 @@ return classNames.some(className => |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38511
348