{"name":"jest-emotion","version":"11.0.0-next.7","description":"Jest utilities for emotion","main":"dist/jest-emotion.cjs.js","types":"types/index.d.ts","scripts":{"test:typescript":"dtslint types"},"dependencies":{"@babel/runtime":"^7.7.2","@types/jest":"^24.0.22","chalk":"^2.4.1","css":"^2.2.1","specificity":"^0.4.1"},"devDependencies":{"@emotion/core":"^11.0.0-next.7","dtslint":"^0.3.0","emotion":"^11.0.0-next.0","enzyme-to-json":"^3.2.1","preact":"^8.2.9","preact-render-to-json":"^3.6.6","pretty-format":"^22.4.3","react":"^16.11.0","react-dom":"^16.11.0"},"author":{"name":"Kye Hohenberger"},"homepage":"https://emotion.sh","license":"MIT","repository":{"type":"git","url":"https://github.com/emotion-js/emotion/tree/master/packages/jest-emotion"},"keywords":["styles","emotion","react","css","css-in-js","jest","snapshot"],"bugs":{"url":"https://github.com/emotion-js/emotion/issues"},"browser":{"./dist/jest-emotion.cjs.js":"./dist/jest-emotion.browser.cjs.js"},"readme":"# jest-emotion\n\n> Jest testing utilities for emotion\n\n# Installation\n\n```bash\nnpm install --save-dev jest-emotion\n```\n\n# Snapshot Serializer\n\nThe easiest way to test React components with emotion is with the snapshot serializer. You can register the serializer via the `snapshotSerializers` configuration property in your jest configuration like so:\n\n```js\n// jest.config.js\nmodule.exports = {\n  // ... other config\n  snapshotSerializers: [\n    'jest-emotion' /* if needed other snapshotSerializers should go here */\n  ]\n}\n```\n\nOr you can customize the serializer via the `createSerializer` method like so: (the example below is with react-test-renderer but jest-emotion also works with enzyme and react-testing-library)\n\n```jsx\nimport React from 'react'\nimport renderer from 'react-test-renderer'\nimport serializer from 'jest-emotion'\nimport styled from '@emotion/styled'\n\nexpect.addSnapshotSerializer(serializer)\n\ntest('renders with correct styles', () => {\n  const H1 = styled.h1`\n    float: left;\n  `\n\n  const tree = renderer.create(<H1>hello world</H1>).toJSON()\n\n  expect(tree).toMatchSnapshot()\n})\n```\n\nRefer to the [testing doc](https://github.com/emotion-js/emotion/blob/master/docs/testing.md) for more information about snapshot testing with emotion.\n\n## Options\n\n### `classNameReplacer`\n\njest-emotion'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.\n\n```jsx\nfunction classNameReplacer(className, index) {\n  return `emotion-${index}`\n}\n```\n\n```jsx\nimport { createSerializer } from 'jest-emotion'\n\nexpect.addSnapshotSerializer(\n  createSerializer({\n    classNameReplacer(className, index) {\n      return `my-new-class-name-${index}`\n    }\n  })\n)\n```\n\n### `DOMElements`\n\njest-emotion'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:\n\n```jsx\nimport { createSerializer } from 'jest-emotion'\n\n// configures jest-emotion to ignore DOM elements\nexpect.addSnapshotSerializer(createSerializer({ DOMElements: false }))\n```\n\n# Custom matchers\n\n## toHaveStyleRule\n\nTo make more explicit assertions when testing your styled components you can use the `toHaveStyleRule` matcher.\n\n```jsx\nimport React from 'react'\nimport renderer from 'react-test-renderer'\nimport { matchers } from 'jest-emotion'\nimport styled from '@emotion/styled'\n\n// Add the custom matchers provided by 'jest-emotion'\nexpect.extend(matchers)\n\ntest('renders with correct styles', () => {\n  const Svg = styled('svg')`\n    width: 100%;\n  `\n\n  const Div = styled('div')`\n    float: left;\n    height: 80%;\n    &:hover {\n      width: 50px;\n    }\n    ${Svg} {\n      fill: green;\n    }\n    span {\n      color: yellow;\n    }\n    @media screen and (max-width: 1200px) {\n      font-size: 14px;\n    }\n  `\n\n  const tree = renderer\n    .create(\n      <Div>\n        <Svg />\n        <span>Test</span>\n      </Div>\n    )\n    .toJSON()\n\n  expect(tree).toHaveStyleRule('float', 'left')\n  expect(tree).not.toHaveStyleRule('height', '100%')\n})\n```\n\nYou can provide additional options for `toHaveStyleRule` matcher.  \n`target` - helps to specify css selector or other component\nwhere style rule should be found.\n\n```js\nexpect(tree).toHaveStyleRule('width', '50px', { target: ':hover' })\n```\n\n```js\nexpect(tree).toHaveStyleRule('color', 'yellow', { target: 'span' })\n```\n\n```js\nexpect(tree).toHaveStyleRule('fill', 'green', { target: `${Svg}` })\n```\n\n`media` - specifies the media rule where the matcher\nshould look for the style property.\n\n```js\nexpect(tree).toHaveStyleRule('font-size', '14px', {\n  media: 'screen and (max-width: 1200px)'\n})\n```\n\nUse `media` and `target` options to assert on rules within media queries and to target nested components, pseudo-classes, and pseudo-elements.\n\n```jsx\nimport React from 'react'\nimport renderer from 'react-test-renderer'\nimport { matchers } from 'jest-emotion'\nimport styled from '@emotion/styled'\n\n// Add the custom matchers provided by 'jest-emotion'\nexpect.extend(matchers)\n\ntest('renders with correct link styles', () => {\n  const Container = styled.div`\n    font-size: 14px;\n\n    a {\n      color: yellow;\n    }\n\n    a:hover {\n      color: black;\n    }\n\n    @media (min-width: 768px) {\n      font-size: 16px;\n    }\n  `\n\n  const tree = renderer.create(<Container>hello world</Container>).toJSON()\n\n  expect(tree).toHaveStyleRule('color', 'yellow', { target: /a$/ })\n  expect(tree).toHaveStyleRule('color', 'black', { target: 'a:hover' })\n  expect(tree).toHaveStyleRule('font-size', '16px', {\n    media: '(min-width: 768px)'\n  })\n})\n```\n\n## Thanks\n\nThanks to [Kent C. Dodds](https://twitter.com/kentcdodds) who wrote [jest-glamor-react](https://github.com/kentcdodds/jest-glamor-react) which this library is largely based on. ❤️\n","readmeFilename":"README.md","_id":"jest-emotion@11.0.0-next.7","_nodeVersion":"10.17.0","_npmVersion":"6.10.2","dist":{"integrity":"sha512-RiKoVMk2JaTDxu59m/CsEbxMlygOZadwbQaRNZ2Pjd+4H0yDezMpFH+m/+95C6yyGrG7f1hJjSh9RTOFYQXnXA==","shasum":"5706497b9ed014bcdd758ec73ed21cd0fad601e5","tarball":"http://registry-npm.ywwl.com/jest-emotion/download/jest-emotion-11.0.0-next.7.tgz","fileCount":17,"unpackedSize":66488,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJd3ZRoCRA9TVsSAnZWagAAcDQP/1YS1oSe2rvmhskfoalI\n1MsFWAsKcc/7z0go7/dZkeeYtY2PIZpa41qltgAXh+Fxf7h7Hfsiho/SLVMO\nnkQn7M0dgq3Iqki2mWcgsQhp69mXCnbNaBS8QySEbkfgph+l4CZW6VwJMcw3\nbSjgzxHH9X1vHHmMMEtpu0exTj1kYvhCxs5Ck1hOhBcUXw3sFE2WtxI0l12v\nEMZX1Di1a0ZVk2pJ2E6XpXrcyAqD/pQNZog5aomU2POl1cVSsM4RX9ozAG9w\ncex1CVc4mhEuvEGMeC5De/z4WlfkNqFBNA1R77yP4cjvNL6zTvg1ZNU4m86X\nxRzvBA/Q3eVgmkU9SoA/c9Z6VtaQso0ZWGFv7nNZSZnP4ylF2thvIDnyizLk\n7pKBAeSHfkbBC+EjAX8H9rMURezMvHYzuaPzzNsvBhgCDeFZGnYx/pp3qM5J\nnxLeR65KszFlYgit4raHpVa8Twj8nOrg/rzbS+JiBUkzCHA4z9qFG9LTjfIb\nQ/jYD4SOuCjDnxwVUPeuful4YszPPENcdL13rzZoHxn4vVdkpIEveylhg0rP\nZdHgRovoZK1rufQJrITkXdDHe4fH1OwHDWYXQXAxPYdvBviGX9uHNh1w+9Ul\nIn1+ac1OoCV0C2ZBkLb7c+plMwffWTmJXFM+iAJTfZoeTXdVyMJ1EZJOsOJo\nHxmD\r\n=aeB2\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDjfS4yYsmi5VhWqqvJxOeVLu6UcrvUWZCqHpqf1vsfZgIhAIguIWopb1RVzWb4t8jKdoJhTo7hQH9swDq+1TpDDWJK"}],"size":12642,"noattachment":false,"key":"/jest-emotion/-/jest-emotion-11.0.0-next.7.tgz"},"maintainers":[{"email":"mitchell+emotion-release-bot@hamil.town","name":"emotion-release-bot"},{"email":"mitchell@mitchellhamilton.me","name":"mitchellhamilton"},{"email":"kye.hohenberger@gmail.com","name":"tkh44"}],"_npmUser":{"name":"emotion-release-bot","email":"mitchell+emotion-release-bot@hamil.town"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/jest-emotion_11.0.0-next.7_1574802536148_0.47010880617997586"},"_hasShrinkwrap":false,"publish_time":1574802536276,"_cnpm_publish_time":1574802536276,"dist-tags":{"latest":"11.0.0","next":"11.0.0-next.10","rc":"11.0.0-rc.0"}}