Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jest-styled-components

Package Overview
Dependencies
Maintainers
2
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-styled-components - npm Package Compare versions

Comparing version 4.5.0 to 4.6.0

4

CHANGELOG.md

@@ -7,2 +7,6 @@ # Changelog

## [4.5.0](https://github.com/styled-components/jest-styled-components/compare/v4.4.1...v4.5.0) - 2017-09-05
### Changed
- [toHaveStyleRule (React)] Make the matcher compatible with Jest v21 (see https://github.com/facebook/jest/pull/3972).
## [4.4.1](https://github.com/styled-components/jest-styled-components/compare/v4.4.0...v4.4.1) - 2017-08-19

@@ -9,0 +13,0 @@ ### Fixed

6

package.json
{
"name": "jest-styled-components",
"version": "4.5.0",
"version": "4.6.0",
"description": "Jest utilities for Styled Components",

@@ -19,3 +19,3 @@ "main": "./src/index.js",

"devDependencies": {
"babel-jest": "^20.0.3",
"babel-jest": "^21.0.2",
"babel-preset-es2015": "^6.24.1",

@@ -32,3 +32,3 @@ "babel-preset-react": "^6.24.1",

"husky": "^0.14.3",
"jest": "^20.0.4",
"jest": "^21.0.2",
"lint-staged": "^4.0.1",

@@ -35,0 +35,0 @@ "prettier": "^1.5.2",

const css = require('css')
const { getCSS, getHashes } = require('./utils')
const getClassNames = node => {
let classNames = new Set()
const KEY = '__jest-styled-components__'
if (node.children) {
node.children
.slice()
.reverse()
.forEach(
child =>
(classNames = new Set([...getClassNames(child), ...classNames]))
)
const getNodes = (node, nodes = []) => {
if (typeof node === 'object') {
nodes.push(node)
}
if (node.props && node.props.className) {
classNames = new Set([
...node.props.className.trim().split(/\s+/),
...classNames,
])
if (node.children) {
node.children.forEach(child => getNodes(child, nodes))
}
return classNames
return nodes
}
const markNodes = nodes => nodes.forEach(node => (node[KEY] = true))
const getClassNames = nodes =>
nodes.reduce((classNames, node) => {
if (node.props && node.props.className) {
node.props.className
.trim()
.split(/\s+/)
.forEach(className => classNames.add(className))
}
return classNames
}, new Set())
const filterClassNames = (classNames, hashes) =>

@@ -85,12 +89,11 @@ classNames.filter(className => hashes.includes(className))

test(val) {
return (
val && !val.withStyle && val.$$typeof === Symbol.for('react.test.json')
)
return val && !val[KEY] && val.$$typeof === Symbol.for('react.test.json')
},
print(val, print) {
val.withStyle = true
const nodes = getNodes(val)
markNodes(nodes)
const hashes = getHashes()
let classNames = [...getClassNames(val)]
let classNames = [...getClassNames(nodes)]
classNames = filterClassNames(classNames, hashes)

@@ -97,0 +100,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc