{"id":15552367,"url":"https://github.com/bahmutov/cypress-aliases","last_synced_at":"2025-09-28T23:31:50.710Z","repository":{"id":63375220,"uuid":"567379940","full_name":"bahmutov/cypress-aliases","owner":"bahmutov","description":"A plugin that makes working with Cypress aliases much simpler","archived":false,"fork":false,"pushed_at":"2024-12-08T18:23:43.000Z","size":653,"stargazers_count":10,"open_issues_count":4,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-11T21:21:59.172Z","etag":null,"topics":["cypress-plugin"],"latest_commit_sha":null,"homepage":"https://cypress.tips/courses/cypress-plugins","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/bahmutov.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}},"created_at":"2022-11-17T17:03:02.000Z","updated_at":"2024-11-30T19:01:33.000Z","dependencies_parsed_at":"2024-01-13T06:53:37.541Z","dependency_job_id":"65ff43d1-4482-4f6a-9971-da94e55d73c8","html_url":"https://github.com/bahmutov/cypress-aliases","commit_stats":{"total_commits":31,"total_committers":2,"mean_commits":15.5,"dds":"0.22580645161290325","last_synced_commit":"251941aba56f18824b393a3c10f540719bc38128"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fcypress-aliases","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fcypress-aliases/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fcypress-aliases/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fcypress-aliases/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bahmutov","download_url":"https://codeload.github.com/bahmutov/cypress-aliases/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231539719,"owners_count":18392333,"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":["cypress-plugin"],"created_at":"2024-10-02T14:17:43.235Z","updated_at":"2025-09-28T23:31:45.401Z","avatar_url":"https://github.com/bahmutov.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cypress-aliases ![cypress version](https://img.shields.io/badge/cypress-12.17.3-brightgreen)\n\n\u003e A plugin that makes working with Cypress aliases much simpler\n\n- 🎓 This plugin is covered by my course [Cypress Plugins](https://cypress.tips/courses/cypress-plugins)\n  - [Lesson g2: Simplify assertions using the alias syntax](https://cypress.tips/courses/cypress-plugins/lessons/g2)\n  - [Lesson g3: Check the text on the page using an alias access](https://cypress.tips/courses/cypress-plugins/lessons/g3)\n  - [Lesson g4: Use resolved aliases to make API requests](https://cypress.tips/courses/cypress-plugins/lessons/g4)\n  - [Lesson g5: Reuse the alias shortcut created in before hook](https://cypress.tips/courses/cypress-plugins/lessons/g5)\n  - [Lesson g6: Get all aliases](https://cypress.tips/courses/cypress-plugins/lessons/g6)\n\n## Install\n\nAdd this plugin as a dev dependency to your project\n\n```shell\n$ npm i -D cypress-aliases\n# or install using Yarn\n$ yarn add -D cypress-aliases\n```\n\n### Cypress version support\n\n| cypress-aliases | Cypress |\n| --------------- | ------- |\n| v1              | \u003c v12   |\n| v2              | \u003e= v12  |\n\n## Use\n\nYou can include all overwritten commands from this plugin by importing just the plugin from your spec or support file:\n\n```js\nimport 'cypress-aliases'\n// same as\nimport 'cypress-aliases/commands'\n```\n\nAlternatively, you can import the individual source files to overwrite the commands you want to automatically resolve the aliases\n\n```js\nimport 'cypress-aliases/commands/should'\nimport 'cypress-aliases/commands/contains'\nimport 'cypress-aliases/commands/wrap'\nimport 'cypress-aliases/commands/request'\nimport 'cypress-aliases/commands/as'\nimport 'cypress-aliases/commands/type'\nimport 'cypress-aliases/commands/all'\n```\n\n## API\n\n### should\n\nAllows you to use aliased values in the `.should(...)` [implicit assertions](https://glebbahmutov.com/cypress-examples/commands/assertions.html).\n\n```js\ncy.wrap(42).as('answer')\ncy.wrap(20 + 22).should('equal', '@answer')\n```\n\nSee [cypress/e2e/should.cy.js](./cypress/e2e/should.cy.js) spec file\n\n### contains\n\nOverwrites the [cy.contains](https://on.cypress.io/contains) command to automatically substitute the resolved aliased values into the text you are looking for.\n\n```html\n\u003cdiv id=\"number\"\u003e42\u003c/div\u003e\n\u003cp\u003eHello there \u003cspan class=\"name\"\u003eCy\u003c/span\u003e\u003c/p\u003e\n```\n\n```js\ncy.wrap('Cy').as('name')\ncy.contains('p', 'Hello there @name')\n```\n\nSee [cypress/e2e/contains.cy.js](./cypress/e2e/contains.cy.js) spec file\n\n## type\n\nYou can type the aliased current value, either by itself or as part of a longer string\n\n```js\ncy.wrap('hello').as('greeting')\ncy.get('#memo').type('@greeting world!')\ncy.get('#memo').should('have.value', 'hello world!')\n```\n\nSee [cypress/e2e/type.cy.js](./cypress/e2e/type.cy.js)\n\n### wrap\n\nOverwrites the [cy.wrap](https://on.cypress.io/wrap) command and resolves all words that start with `@`\n\n```js\ncy.wrap('Hello').as('greeting')\ncy.wrap('world').as('name')\ncy.wrap('@greeting there @name').should('equal', 'Hello there world')\n```\n\nSee [cypress/e2e/wrap.cy.js](./cypress/e2e/wrap.cy.js) spec file.\n\nNote: if you simply want to look up a single aliased value, use [cy.get](https://on.cypress.io/get) instead\n\n```js\ncy.wrap(42).as('n')\ncy.get('@n').should('equal', 42)\n```\n\n### request\n\nOverwrites the [cy.request](https://on.cypress.io/request) command to change the URL using any included aliases\n\n```js\ncy.wrap('posts').as('resource')\ncy.wrap(2).as('postId')\n// makes the request to /api/posts/2\ncy.request('/api/@resource/@postId')\n```\n\nSee [cypress/e2e/request.cy.js](./cypress/e2e/request.cy.js) spec file.\n\n### as\n\nEvery registered Cypress alias is removed before every test. Thus one needs to recreate the aliases before each test. This module overwrites the [cy.as](https://on.cypress.io/as) command to add `keep: true` option. The kept aliases are restored automatically before each test.\n\n```js\nbefore(() =\u003e {\n  cy.request('POST', '/items')\n    .its('body.id')\n    // preserve the alias and restore\n    // it before every future test\n    .as('id', { keep: true })\n})\n\nit('has the item alias', () =\u003e {\n  cy.get('@id')\n})\n\nit('still has the item alias', () =\u003e {\n  cy.get('@id')\n})\n```\n\n### getAllAliases\n\nYields all current aliases\n\n```js\ncy.wrap(1).as('one')\ncy.wrap(2).as('two')\ncy.wrap(3).as('three')\ncy.getAllAliases().should('deep.equal', { one: 1, two: 2, three: 3 })\n```\n\n## Small print\n\nAuthor: Gleb Bahmutov \u0026lt;gleb.bahmutov@gmail.com\u0026gt; \u0026copy; 2022\n\n- [@bahmutov](https://twitter.com/bahmutov)\n- [glebbahmutov.com](https://glebbahmutov.com)\n- [blog](https://glebbahmutov.com/blog)\n- [videos](https://www.youtube.com/glebbahmutov)\n- [presentations](https://slides.com/bahmutov)\n- [cypress.tips](https://cypress.tips)\n- [Cypress Tips \u0026 Tricks Newsletter](https://cypresstips.substack.com/)\n- [my Cypress courses](https://cypress.tips/courses)\n\nLicense: MIT - do anything with the code, but don't blame me if it does not work.\n\nSupport: if you find any problems with this module, email / tweet /\n[open issue](https://github.com/bahmutov/cypress-aliases/issues) on Github\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahmutov%2Fcypress-aliases","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbahmutov%2Fcypress-aliases","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahmutov%2Fcypress-aliases/lists"}