JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4458
  • Score
    100M100P100Q134085F
  • License MIT

Extends Cypress' cy commands with methods for administrating mocks-server

Package Exports

  • @mocks-server/cypress-commands

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@mocks-server/cypress-commands) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Build status Coverage Status Quality Gate

NPM dependencies Renovate Last commit Last release

NPM downloads License

Mocks server Cypress commands

This solution provides you commands for easily changing @mocks-server settings, such as current behavior, delay time, etc.

Installation

This module is distributed via npm and should be installed as one of your project's devDependencies:

npm i --save-dev @mocks-server/cypress-commands

Usage

@mocks-server/cypress-commands extends Cypress' cy command.

Add this line to your project's cypress/support/commands.js:

import "@mocks-server/cypress-commands"

You can now use all next commands:

Commands

Set current behavior:

cy.mocksServerSetBehavior("admin-user");

Set delay time:

cy.mocksServerSetDelay(2000);

Set any setting:

cy.mocksServerSetSettings({
  watch: false,
  delay: 0,
  behavior: "catalog-error"
});

Configuration

By default, the client is configured to request to http://localhost:3100/admin, based in the default options of @mocks-server

You can change both the base url of the "@mocks-server", and the admin api path of the "@mocks-server/plugin-admin-api" using the config method in your project's cypress/support/commands.js:

import { config } from "@mocks-server/cypress-commands";

config({
  adminApiPath: "/foo-admin",
  baseUrl: "http://my-mocks-server:3200"
});

Using commands

You should usually change the mock server settings in a before statement:

describe("user with default role", () => {
  before(() => {
    cy.mocksServerSetBehavior("normal-user");
    cy.visit("/");
  });

  it("should not see the users section link", () => {
    cy.get("#users-section-link").should("not.be.visible");
  });
});

describe("user with admin role", () => {
  before(() => {
    cy.mocksServerSetBehavior("admin-user");
    cy.visit("/");
  });

  it("should see the users section link", () => {
    cy.get("#users-section-link").should("be.visible");
  });
});

Contributing

Contributors are welcome. Please read the contributing guidelines and code of conduct.

License

MIT, see LICENSE for details.