npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cypress-aliases

v2.1.0

Published

A plugin that makes working with Cypress aliases much simpler

Downloads

1,432

Readme

cypress-aliases cypress version

A plugin that makes working with Cypress aliases much simpler

Install

Add this plugin as a dev dependency to your project

$ npm i -D cypress-aliases
# or install using Yarn
$ yarn add -D cypress-aliases

Cypress version support

| cypress-aliases | Cypress | | --------------- | ------- | | v1 | < v12 | | v2 | >= v12 |

Use

You can include all overwritten commands from this plugin by importing just the plugin from your spec or support file:

import 'cypress-aliases'
// same as
import 'cypress-aliases/commands'

Alternatively, you can import the individual source files to overwrite the commands you want to automatically resolve the aliases

import 'cypress-aliases/commands/should'
import 'cypress-aliases/commands/contains'
import 'cypress-aliases/commands/wrap'
import 'cypress-aliases/commands/request'
import 'cypress-aliases/commands/as'
import 'cypress-aliases/commands/type'
import 'cypress-aliases/commands/all'

API

should

Allows you to use aliased values in the .should(...) implicit assertions.

cy.wrap(42).as('answer')
cy.wrap(20 + 22).should('equal', '@answer')

See cypress/e2e/should.cy.js spec file

contains

Overwrites the cy.contains command to automatically substitute the resolved aliased values into the text you are looking for.

<div id="number">42</div>
<p>Hello there <span class="name">Cy</span></p>
cy.wrap('Cy').as('name')
cy.contains('p', 'Hello there @name')

See cypress/e2e/contains.cy.js spec file

type

You can type the aliased current value, either by itself or as part of a longer string

cy.wrap('hello').as('greeting')
cy.get('#memo').type('@greeting world!')
cy.get('#memo').should('have.value', 'hello world!')

See cypress/e2e/type.cy.js

wrap

Overwrites the cy.wrap command and resolves all words that start with @

cy.wrap('Hello').as('greeting')
cy.wrap('world').as('name')
cy.wrap('@greeting there @name').should('equal', 'Hello there world')

See cypress/e2e/wrap.cy.js spec file.

Note: if you simply want to look up a single aliased value, use cy.get instead

cy.wrap(42).as('n')
cy.get('@n').should('equal', 42)

request

Overwrites the cy.request command to change the URL using any included aliases

cy.wrap('posts').as('resource')
cy.wrap(2).as('postId')
// makes the request to /api/posts/2
cy.request('/api/@resource/@postId')

See cypress/e2e/request.cy.js spec file.

as

Every registered Cypress alias is removed before every test. Thus one needs to recreate the aliases before each test. This module overwrites the cy.as command to add keep: true option. The kept aliases are restored automatically before each test.

before(() => {
  cy.request('POST', '/items')
    .its('body.id')
    // preserve the alias and restore
    // it before every future test
    .as('id', { keep: true })
})

it('has the item alias', () => {
  cy.get('@id')
})

it('still has the item alias', () => {
  cy.get('@id')
})

getAllAliases

Yields all current aliases

cy.wrap(1).as('one')
cy.wrap(2).as('two')
cy.wrap(3).as('three')
cy.getAllAliases().should('deep.equal', { one: 1, two: 2, three: 3 })

Small print

Author: Gleb Bahmutov <[email protected]> © 2022

License: MIT - do anything with the code, but don't blame me if it does not work.

Support: if you find any problems with this module, email / tweet / open issue on Github