jest-styled-components
Advanced tools
Comparing version 3.2.2 to 3.3.0
{ | ||
"name": "jest-styled-components", | ||
"version": "3.2.2", | ||
"version": "3.3.0", | ||
"description": "Jest utilities for Styled Components", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
@@ -6,3 +6,3 @@ const css = require('css') | ||
const getClassName = (received) => { | ||
const getClassNames = (received) => { | ||
let className = '' | ||
@@ -16,12 +16,20 @@ | ||
return `.${className.split(/\s/).pop()}` | ||
return className.split(/\s/) | ||
} | ||
const getRules = (ast, className) => ast.stylesheet.rules.filter( | ||
rule => rule.type === 'rule' && rule.selectors.includes(className) | ||
const hasRule = (classNames, selectors) => classNames.some( | ||
className => selectors.includes(`.${className}`) | ||
) | ||
const getDeclarations = (rule, property) => rule.declarations.filter( | ||
const getRules = (ast, classNames) => ast.stylesheet.rules.filter( | ||
rule => rule.type === 'rule' && hasRule(classNames, rule.selectors) | ||
) | ||
const getDeclaration = (rule, property) => rule.declarations.filter( | ||
declaration => declaration.type === 'declaration' && | ||
declaration.property === property | ||
)[0] | ||
const getDeclarations = (rules, property) => rules.map( | ||
rule => getDeclaration(rule, property) | ||
) | ||
@@ -34,7 +42,7 @@ | ||
function toHaveStyleRule(received, property, value) { | ||
const className = getClassName(received) | ||
const toHaveStyleRule = (received, property, value) => { | ||
const classNames = getClassNames(received) | ||
const styles = getCSS(styleSheet) | ||
const ast = css.parse(styles) | ||
const rules = getRules(ast, className) | ||
const rules = getRules(ast, classNames) | ||
@@ -45,3 +53,3 @@ if (!rules.length) { | ||
const declarations = getDeclarations(rules[0], property) | ||
const declarations = getDeclarations(rules, property) | ||
@@ -52,3 +60,3 @@ if (!declarations.length) { | ||
const declaration = declarations[0] | ||
const declaration = declarations.pop() | ||
@@ -55,0 +63,0 @@ const message = |
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
14701
281