{"id":13725704,"url":"https://github.com/thymikee/linaria-jest","last_synced_at":"2025-03-21T07:31:05.554Z","repository":{"id":46938716,"uuid":"107324236","full_name":"thymikee/linaria-jest","owner":"thymikee","description":"🃏 Jest utilities for Linaria","archived":false,"fork":false,"pushed_at":"2022-12-07T09:17:19.000Z","size":512,"stargazers_count":16,"open_issues_count":17,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-01T04:03:10.314Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thymikee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-17T21:09:02.000Z","updated_at":"2022-06-09T18:31:19.000Z","dependencies_parsed_at":"2023-01-23T16:45:38.180Z","dependency_job_id":null,"html_url":"https://github.com/thymikee/linaria-jest","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thymikee%2Flinaria-jest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thymikee%2Flinaria-jest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thymikee%2Flinaria-jest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thymikee%2Flinaria-jest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thymikee","download_url":"https://codeload.github.com/thymikee/linaria-jest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244119816,"owners_count":20401054,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T01:02:31.929Z","updated_at":"2025-03-21T07:31:05.189Z","avatar_url":"https://github.com/thymikee.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Jest utilities for [Linaria](https://github.com/callstack/linaria)\n\nA set of utilities for more delightful testing of Linaria–enhanced code with Jest.\n\n## API\n* `reactSerializer` – React snapshot serializer\n* `preactSerializer` – Preact snapshot serializer\n\n## Snapshot serializers\n\nOne of the most helpful utilities for CSS in JS libraries are [snapshot serialiers](http://facebook.github.io/jest/docs/en/expect.html#expectaddsnapshotserializerserializer), which are able to colocate styles with JS code. Linaria provides serializers for React and Preact components by default.\n\n### Usage\n\nUse it directly in your test file, or in `setupFiles`:\n\n```js\nimport { reactSerializer } from 'linaria-jest';\n\nexpect.addSnapshotSerializer(reactSerializer);\n```\n\nMake sure you **turn off** `linaria/babel` preset for testing purposes, otherwise it won't work.\nE.g. change this:\n\n```json\n{\n  \"presets\": [\"env\", \"react\", \"linaria/babel\"],\n}\n```\n\n...to this:\n\n```json\n{\n  \"presets\": [\"env\", \"react\"],\n  \"env\": {\n    \"development\": {\n      \"presets\": [\"linaria/babel\"]\n    },\n    \"production\": {\n      \"presets\": [\"linaria/babel\"]\n    }\n  }\n}\n```\n\n### Example\n\nHere's a component we want to snapshot:\n\n```jsx\nimport React from 'react';\nimport { css, names } from 'linaria';\nimport theme from '../theme';\n\nexport default function Container({ children, className }) {\n  return \u003cdiv className={names(container, className)}\u003e{children}\u003c/div\u003e;\n}\n\nconst container = css`\n  max-width: 900px;\n\n  \u0026:hover {\n    background: ${theme.hover};\n  }\n`;\n```\n\nWe write a test (provided that our serializer is added in `setupFiles`):\n\n```jsx\nimport React from 'react';\nimport { css } from 'linaria';\n\ntest('my pretty Container', () =\u003e {\n  const tree = renderer.create(\n    \u003cContainer className={css`flex: 1;`}\u003etext\u003c/Container\u003e;\n  );\n\n  expect(tree).toMatchSnapshot();\n});\n```\n\n...and the output snapshot with serializer applied is:\n\n```js\n// Jest Snapshot v1, https://goo.gl/fbAQLP\n\nexports[`my pretty Container 1`] = `\n.a0 {\n  max-width: 900px;\n}\n.a0:hover {\n  background: #fff;\n}\n.a1 {\n  -webkit-flex: 1;\n  -ms-flex: 1;\n  flex: 1;\n}\n\n\u003cdiv\n  className=\"a0 a1\"\n\u003e\n  text\n\u003c/div\u003e\n`\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthymikee%2Flinaria-jest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthymikee%2Flinaria-jest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthymikee%2Flinaria-jest/lists"}