Skip to content

Commit

Permalink
reorder functions
Browse files Browse the repository at this point in the history
  • Loading branch information
MicheleBertoli committed Oct 23, 2017
1 parent 946a894 commit 733ae27
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/toHaveStyleRule.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
const { getCSS } = require('./utils')

const hasAtRule = options =>
Object.keys(options).some(option => ['media', 'supports'].includes(option))

const shouldDive = node =>
typeof node.type() !== 'string' && 'innerRef' in node.props()

Expand All @@ -24,12 +21,8 @@ const getClassNames = received => {
return className ? className.split(/\s/) : []
}

const hasClassNames = (classNames, selectors, options) =>
classNames.some(className =>
selectors.includes(
`.${className}${options.modifier ? `${options.modifier}` : ''}`
)
)
const hasAtRule = options =>
Object.keys(options).some(option => ['media', 'supports'].includes(option))

const getAtRules = (ast, options) =>
Object.keys(options)
Expand All @@ -43,6 +36,13 @@ const getAtRules = (ast, options) =>
)
.reduce((acc, rules) => acc.concat(rules), [])

const hasClassNames = (classNames, selectors, options) =>
classNames.some(className =>
selectors.includes(
`.${className}${options.modifier ? `${options.modifier}` : ''}`
)
)

const getRules = (ast, classNames, options) => {
const rules = hasAtRule(options)
? getAtRules(ast, options)
Expand All @@ -54,6 +54,11 @@ const getRules = (ast, classNames, options) => {
)
}

const die = (utils, property) => ({
pass: false,
message: () => `Property not found: ${utils.printReceived(property)}`,
})

const getDeclaration = (rule, property) =>
rule.declarations
.filter(
Expand All @@ -65,11 +70,6 @@ const getDeclaration = (rule, property) =>
const getDeclarations = (rules, property) =>
rules.map(rule => getDeclaration(rule, property)).filter(Boolean)

const die = (utils, property) => ({
pass: false,
message: () => `Property not found: ${utils.printReceived(property)}`,
})

function toHaveStyleRule(received, property, value, options = {}) {
const classNames = getClassNames(received)
const ast = getCSS()
Expand Down

0 comments on commit 733ae27

Please sign in to comment.