Catalog npm
Back to packageRELEASE DETAILS

1.1.1

npm

@-ui/jest

Jest utilities for dash-ui

-uicssdashdash uijestjest assertionsjest css serializerjest pluginjest serializer
Published22 Apr 2020
Direct dependencies24
Transitive dependenciesNot calculated

README

Current package documentation

@-ui/jest

Code coverage Build status NPM Version MIT License

npm i -D @-ui/jest

Jest utilities for -ui

-ui snapshots

The easiest way to test React, Preact, and Preact X components with -ui is using the snapshot serializer. You can register the serializer via the snapshotSerializers configuration property in your jest configuration like so:

// jest.config.js
module.exports = {
  // ... other config
  snapshotSerializers: ['@-ui/jest'],
}

Or you can customize the serializer via the createSerializer method like so: (the example below is with react-test-renderer but @-ui/jest also works with enzyme and react-testing-library)

import React from 'react'
import renderer from 'react-test-renderer'
import styles from '@-ui/styles'
import serializer from '@-ui/jest'

expect.addSnapshotSerializer(serializer)

test('renders with correct styles', () => {
  const text = styles({
    heading: `
      font-size: 4rem;
    `,
  })

  const tree = renderer
    .create(<h1 className={text('heading')}>Hello world</h1>)
    .toJSON()

  expect(tree).toMatchSnapshot()
})

Options

classNameReplacer

@-ui/jest's snapshot serializer replaces the hashes in class names with an index so that things like whitespace changes won't break snapshots. It optionally accepts a custom class name replacer, it defaults to the below.

const classNameReplacer = (className, index) => `-ui-${index}`
import {createSerializer} from '@-ui/jest'

expect.addSnapshotSerializer(
  createSerializer({
    classNameReplacer(className, index) {
      return `my-new-class-name-${index}`
    },
  })
)

DOMElements

@-ui/jest's snapshot serializer inserts styles and replaces class names in both React and DOM elements. If you would like to disable this behavior for DOM elements, you can do so by passing { DOMElements: false }. For example:

import {createSerializer} from '@-ui/jest'

// configures @-ui/jest to ignore DOM elements
expect.addSnapshotSerializer(createSerializer({DOMElements: false}))

Custom assertions

toHaveStyleRule

To make more explicit assertions when testing your components you can use the toHaveStyleRule matcher.

import React from 'react'
import renderer from 'react-test-renderer'
import {matchers} from '@-ui/jest'

// Add the custom matchers provided by '@-ui/jest'
expect.extend(matchers)

test('renders with correct styles', () => {
  const text = styles({
    heading: `
      font-size: 4rem;
    `,
  })

  const tree = renderer
    .create(<h1 className={text('heading')}>Hello world</h1>)
    .toJSON()

  expect(tree).toHaveStyleRule('font-size', '4rem')
  expect(tree).not.toHaveStyleRule('color', 'hotpink')
})

Credit

This was inspired by and relies almost entirely on work by jest-emotion which was largely inspired by jest-glamor-react.

LICENSE

MIT

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 24

Native requirements
24 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
chalk
Environment
{
  "local_name": "chalk",
  "alias": false,
  "peer_metadata": null
}
^3.0.0runtime
css
Environment
{
  "local_name": "css",
  "alias": false,
  "peer_metadata": null
}
^2.2.4runtime
@-ui/styles
Environment
{
  "local_name": "@-ui/styles",
  "alias": false,
  "peer_metadata": null
}
^1.0.37development
@babel/preset-react
Environment
{
  "local_name": "@babel/preset-react",
  "alias": false,
  "peer_metadata": null
}
^7.7.0development
@lunde/babel-preset-es
Environment
{
  "local_name": "@lunde/babel-preset-es",
  "alias": false,
  "peer_metadata": null
}
latestdevelopment
babel-eslint
Environment
{
  "local_name": "babel-eslint",
  "alias": false,
  "peer_metadata": null
}
latestdevelopment
cross-env
Environment
{
  "local_name": "cross-env",
  "alias": false,
  "peer_metadata": null
}
latestdevelopment
enzyme
Environment
{
  "local_name": "enzyme",
  "alias": false,
  "peer_metadata": null
}
^3.10.0development
enzyme-adapter-react-16
Environment
{
  "local_name": "enzyme-adapter-react-16",
  "alias": false,
  "peer_metadata": null
}
^1.15.1development
enzyme-to-json
Environment
{
  "local_name": "enzyme-to-json",
  "alias": false,
  "peer_metadata": null
}
^3.4.3development
eslint
Environment
{
  "local_name": "eslint",
  "alias": false,
  "peer_metadata": null
}
latestdevelopment
eslint-import-resolver-jest
Environment
{
  "local_name": "eslint-import-resolver-jest",
  "alias": false,
  "peer_metadata": null
}
latestdevelopment
eslint-plugin-jest
Environment
{
  "local_name": "eslint-plugin-jest",
  "alias": false,
  "peer_metadata": null
}
latestdevelopment
husky
Environment
{
  "local_name": "husky",
  "alias": false,
  "peer_metadata": null
}
latestdevelopment
jest
Environment
{
  "local_name": "jest",
  "alias": false,
  "peer_metadata": null
}
latestdevelopment
lint-staged
Environment
{
  "local_name": "lint-staged",
  "alias": false,
  "peer_metadata": null
}
latestdevelopment
preact
Environment
{
  "local_name": "preact",
  "alias": false,
  "peer_metadata": null
}
10development
preact-render-to-json
Environment
{
  "local_name": "preact-render-to-json",
  "alias": false,
  "peer_metadata": null
}
^3.6.6development
prettier
Environment
{
  "local_name": "prettier",
  "alias": false,
  "peer_metadata": null
}
latestdevelopment
pretty-format
Environment
{
  "local_name": "pretty-format",
  "alias": false,
  "peer_metadata": null
}
^24.9.0development
react
Environment
{
  "local_name": "react",
  "alias": false,
  "peer_metadata": null
}
^16.12.0development
react-dom
Environment
{
  "local_name": "react-dom",
  "alias": false,
  "peer_metadata": null
}
^16.12.0development
react-test-renderer
Environment
{
  "local_name": "react-test-renderer",
  "alias": false,
  "peer_metadata": null
}
^16.12.0development
rimraf
Environment
{
  "local_name": "rimraf",
  "alias": false,
  "peer_metadata": null
}
^2.6.3development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "d0c866e2ff9db2ff9c0035d3197163e7b897b902",
  "integrity": "sha512-4n7hJlXzbjMcIOzyBtups8YQpyGLHHENsmr9XgaQ5oLeSg2pu7Bg4y4w/hn9XXEQKoyDsuuw1BHP5XVRKNyHKg==",
  "tarball": "https://registry.npmjs.org/@-ui/jest/-/jest-1.1.1.tgz",
  "fileCount": 8,
  "unpackedSize": 20459,
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeoKwJCRA9TVsSAnZWagAAffcQAJN/cxIgCa5acXFvQTez\nAC5PJVxlIY4LYpWpK7r3d/rzwrr/LY1gzZe+LJ62Kp2P+ASq4vxNSHt8ovEa\nAe+gGxOLDB/5mXba9tZSQIRH+7Pze1/P3rBzcZCpB0pDkz+wPUEKEBd/ymdq\n5mCqWx1NKCRtHo1Bih6visJjrBg+qieCcWibNEVtsVEz1sRz7pnF1MT+v5wU\noBgvFRsoIhWCoJY9v6eQ5FFpA1+4CAkoGEn+qg9Raw7WcjJu9IqNtlKx4lrV\nY6BrtlvPMypd4kKL2XNYe9bnp9n3vnlZ2tSOP9+0BCUJG69RKpkkdMQrqTvN\nah5wdJfm8ihlrvyOrp6oz8uf0MDun2xRlwe5KDHAwBQ866rqIOQIVsX0S5ik\naRV5ojjvAzzXRk3Z+Xr/8hQkAw84st011e5HbYzXkeorWs4Od2V3cmi/f+Aj\nxKLX58CdsUgeFCt8wd5V+z2gNtaMIhs6YP4kohyek9H5YBcUJ16Zm9nwoZA8\nTTExqaPFmSKdcwMefQ4/HHmxn066xKZ1AwOzJEjESSO9tNJHMi75J6dO5H/+\nYhu34pe1UbwQ5dqk3xfIXFjJTEMm9qUFpupZ2uDvbKE7VnIDBFUtKJqI66Ii\nmoMgCPXQ0m5awRGG1wGZ+NZkZU5LHDTPEkWWyvAYl+SDy4tkF39PWFSKKtPt\nxwz1\r\n=+oiW\r\n-----END PGP SIGNATURE-----\r\n",
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEQCIH9KjIRmm7qcfVCrg3hFMlPrMiXzJYvn98Nv8dMVrBpnAiBjJgbWzBLGOZol6XKCj2d+RQCbDpVn4uwR8/rX9b76ZA=="
    }
  ]
}

Repository

PENDING
dash-ui/jest

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 21:49 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:a5e0aebae6ff0bbcd3a93e508fd2734a90d69480e4b7c7ce23538aabed771dde

Other collected versions

1.1.022 Apr1.0.116 Nov1.0.015 NovView all collected versions →