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 🙏

© 2025 – Pkg Stats / Ryan Hefner

cypress-wait-on-last

v1.1.2

Published

Wait for the last matched Cypress alias, with optional validation. Continuously checks the latest matching interception and only returns when valid. Useful for handling unknown request counts or race conditions.

Readme

cypress-wait-on-last

Wait for the last matched aliased interception. Allows validation of the alias's content with an optional validation function. Continuously rechecks the newest matching aliased cypress interception and only returns when it is considered valid. Useful for when an unknown number of requests are expected, or race condition issues are present.

Installation

npm install cypress-wait-on-last

Setup

In your cypress/support/e2e.js:

import "cypress-wait-on-last";

Usage

The waitOnLast command waits for a network request and optionally validates its response data before proceeding.

Basic Usage - Wait for Last Request

// Intercept a request
cy.intercept("GET", "/api/data").as("getData");

// Wait for the last request (no validation)
cy.waitOnLast("@getData");

Basic Usage - Wait with Validation

// Intercept a request
cy.intercept("GET", "/api/data").as("getData");

// Wait for the request and validate the response
cy.waitOnLast("@getData", (data) => {
  expect(data.response.body.status).to.eq("success");
});

Advanced Usage

cy.intercept("POST", "/api/submit").as("submitForm");

cy.waitOnLast(
  "@submitForm",
  (data) => {
    return (
      data.response?.body?.status === "completed" &&
      data.response?.body?.id !== undefined
    );
  },
  {
    requireValidation: true, // true is default
    displayMessage: "Waiting for form submission to complete",
    errorMessage: "Form submission failed to complete",
    timeout: 10000,
  }
);

API

cy.waitOnLast(alias, validate?, options?)

Parameters

  • alias (string): The alias of the intercepted request
  • validate (function, optional): A function that takes the response data and returns a boolean. If omitted, simply waits for the last request without validation.
  • options (object, optional): Configuration options

Command Configuration Options

  • requireValidation (boolean, default: true): Whether to require validation to pass. When false returns the last matching alias object ignoring validation.
  • displayMessage (string, optional): Custom message to display in Cypress logs
  • errorMessage (string, optional): Custom error message when validation fails
  • timeout (number, optional): Custom timeout for each attempt (defaults to Cypress.config("defaultCommandTimeout") / 60)

Returns

Returns the most recent response data. When requireValidation is true (default), returns the most recent response if it is valid.

Examples

Waiting for Last Request (No Validation)

cy.intercept("GET", "/api/users").as("getUsers");

// Simply wait for the latest matching request to complete
cy.waitOnLast("@getUsers");

Waiting for API Response with Specific Data

cy.intercept("GET", "/api/users").as("getUsers");

cy.waitOnLast("@getUsers", (data) => {
  return (
    data.response?.body?.users &&
    data.response?.body?.users.some((user) => user.name === "John Doe")
  );
});

Waiting for Status Change

cy.intercept("GET", "/api/job/*/status").as("getJobStatus");

cy.waitOnLast(
  "@getJobStatus",
  (data) => {
    return data.response?.body?.status === "completed";
  },
  {
    timeout: 15000,
    displayMessage: "Job status is completed",
    errorMessage: "Final request was not 'completed'",
  }
);

Handling Complex Validation

cy.intercept("POST", "/api/process").as("processData");

cy.waitOnLast(
  "@processData",
  (data) => {
    return (
      data.response?.body?.result &&
      data.response?.body?.result.progress === 100 &&
      data.response?.body?.result.errors.length === 0
    );
  },
  {
    errorMessage: "Data processing failed or has errors",
  }
);

Waiting for Multiple Requests

cy.intercept("GET", "/api/data").as("getData");

// Trigger multiple requests
cy.visit("/page");
cy.get('[data-testid="refresh"]').click();
cy.get('[data-testid="refresh"]').click();

// Wait for the last request to complete
cy.waitOnLast("@getData").then((response) => {
  // Work with the most recent response
  console.log("Latest data:", response);
});

TypeScript Support

This plugin includes full TypeScript support with type definitions:

interface ExampleApiResponse {
  status: string;
  customField: string;
  data: any[];
  timestamp: number;
}

// With validation
// ExampleApiResponse type is passed to the Cypress interception.response.body
// returnType: Interception<T>, the same type as used in the validation function.
cy.waitOnLast<ExampleApiResponse>("@apiCall", ({ response }) => {
  return (
    response?.body?.status === "success" &&
    response?.body?.data.length > 0 &&
    response?.body?.customField !== undefined
  );
}).then(({ response }) => {
  expect(response).to.not.be.undefined;
  cy.get(".element").should("have.length", response?.body?.data.length);
});

// Without validation
cy.waitOnLast<ExampleApiResponse>("@apiCall").then((data) => {
  console.log(data);
});

License

MIT