{"id":13806905,"url":"https://github.com/simonireilly/cypress-lit","last_synced_at":"2026-02-14T09:01:35.573Z","repository":{"id":62927196,"uuid":"550441108","full_name":"simonireilly/cypress-lit","owner":"simonireilly","description":"Test your Lit elements and native web components in cypress with all the modern browsers","archived":false,"fork":false,"pushed_at":"2025-05-05T20:07:43.000Z","size":631,"stargazers_count":24,"open_issues_count":12,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-05T21:25:07.382Z","etag":null,"topics":["custom-elements","cypress","html","lit-element","test","testing","testing-tools","web-components","webcomponents"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/simonireilly.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-10-12T19:18:26.000Z","updated_at":"2024-10-18T07:23:42.000Z","dependencies_parsed_at":"2024-05-03T11:14:27.967Z","dependency_job_id":"a5c3bfcf-c1df-48c0-b486-d3e9251c10a2","html_url":"https://github.com/simonireilly/cypress-lit","commit_stats":{"total_commits":115,"total_committers":4,"mean_commits":28.75,"dds":0.05217391304347829,"last_synced_commit":"315b51dd0970144bd7f74acf11a4cf9dd72996a7"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonireilly%2Fcypress-lit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonireilly%2Fcypress-lit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonireilly%2Fcypress-lit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonireilly%2Fcypress-lit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simonireilly","download_url":"https://codeload.github.com/simonireilly/cypress-lit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254043218,"owners_count":22004912,"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":["custom-elements","cypress","html","lit-element","test","testing","testing-tools","web-components","webcomponents"],"created_at":"2024-08-04T01:01:17.805Z","updated_at":"2026-02-14T09:01:35.447Z","avatar_url":"https://github.com/simonireilly.png","language":"TypeScript","funding_links":[],"categories":["Meta Frameworks"],"sub_categories":["Testing Solutions"],"readme":"# cypress-lit\n\n[![NPM Version](https://img.shields.io/npm/v/cypress-lit.svg?style=for-the-badge\u0026labelColor=000000)](https://www.npmjs.com/package/cypress-lit)\n\nRunning cypress component testing on web components and lit elements.\n\n- [cypress-lit](#cypress-lit)\n  - [Installation](#installation)\n    - [Setup](#setup)\n  - [Examples](#examples)\n    - [With Lit HTML](#with-lit-html)\n    - [With Native WebComponents](#with-native-webcomponents)\n  - [Contributing](#contributing)\n\n\u003e The below gif is slowed by 10x so you don't miss it 🐢\n\n![Cypress runner showing a component test of a lit element](https://user-images.githubusercontent.com/30017294/201855728-a49d5fef-06f7-4c2c-a0d7-f6027e0135d4.gif)\n\n## Installation\n\n```bash\nnpm i -D cypress-lit\nyarn add -D cypress-lit\npnpm i -D cypress-lit\n```\n\n### Setup\n\nThe command needs to be imported from the package and added to cypress commands.\n\n```ts\n# ./cypress/support/component.ts\n\nimport \"./commands\";\n\nimport { mount } from \"cypress-lit\";\n\ndeclare global {\n  namespace Cypress {\n    interface Chainable {\n      mount: typeof mount;\n    }\n  }\n}\n\nCypress.Commands.add(\"mount\", mount);\n```\n\nWhen running cypress components testing you will need to specify a custom dev server. This project has tests that use the below configuration.\n\n```ts\n// ./cypress.config.ts\n\nimport { defineConfig } from \"cypress\";\n\nexport default defineConfig({\n  component: {\n    supportFile: \"cypress/support/component.ts\",\n    devServer: {\n      bundler: \"vite\",\n    },\n    indexHtmlFile: \"cypress/support/component-index.html\",\n  },\n  experimentalWebKitSupport: true,\n});\n```\n\n## Examples\n\nThere is a collection of tests for:\n\n- [Lit Element](./cypress/component/lit.cy.ts)\n- [Pure custom elements](./cypress/component/web-component.cy.ts)\n\n### With Lit HTML\n\nYou can pass a hit template directly to the mount command.\n\n```ts\n// ./cypress/component/lit.cy.ts#L1-L9\n\nimport \"../../templates/index.css\";\nimport { html } from \"lit\";\nimport { LitCounter } from \"../../templates/counter-lit\";\n\ndescribe(\"Lit mount\", () =\u003e {\n  it(\"mounts\", () =\u003e {\n    cy.mount\u003c\"counter-lit\"\u003e(html`\u003ccounter-lit\u003e\u003c/counter-lit\u003e`);\n    cy.get(\"counter-lit\").shadow().contains(\"h1\", \"Count is 0\");\n  });\n```\n\n### With Native WebComponents\n\nIf you have custom elements defined using pure browser javascript then you can pass in a string.\n\n```ts\n// ./cypress/component/web-component.cy.ts#L1-L9\n\nimport { WebCounter } from \"../../templates\";\nimport \"../../templates/index.css\";\n\ndescribe(\"Web Component mount\", () =\u003e {\n  it(\"mounts\", () =\u003e {\n    cy.mount\u003c\"counter-wc\"\u003e(`\u003ccounter-wc\u003e\u003c/counter-wc\u003e`);\n    cy.get(\"counter-wc\").shadow().contains(\"h1\", \"Count is 0\");\n  });\n\n```\n\nWhen using custom elements and you need to access the element to set non-string attributes you can do this using the properties option:\n\n```ts\n// ./cypress/component/web-component.cy.ts#L26-L39\n\nit(\"can pass emitters as spies\", () =\u003e {\n  cy.mount\u003c\"counter-wc\"\u003e(\n    `\u003ccounter-wc\n      count=${42}\n    \u003e\u003c/counter-wc\u003e`,\n    { properties: { clicked: cy.spy().as(\"onClickedSpy\") } },\n  );\n\n  cy.get(\"counter-wc\").shadow().as(\"shadow\");\n\n  cy.get(\"@shadow\").contains(\"h1\", \"Count is 42\");\n  cy.get(\"@shadow\").find(\"button\").click();\n  cy.get(\"@onClickedSpy\").should(\"have.been.calledWith\", 42);\n});\n```\n\nThis enables passing spies and other overrides for testing purposes.\n\n## Contributing\n\nOpen an issue or a PR with some comments to discuss the feat/fix.\n\nFor local running you should be set with:\n\n```bash\npnpm i\npnpm lint\npnpm build\npnpm test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonireilly%2Fcypress-lit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonireilly%2Fcypress-lit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonireilly%2Fcypress-lit/lists"}