Skip to content

@shellygo/cypress-test-utils - v4.1.10 / Modules

@shellygo/cypress-test-utils - v4.1.10

Table of contents

Classes

Type Aliases

Functions

Type Aliases

A11yOptions

Ƭ A11yOptions: { skipFailures?: boolean ; violationCallback?: (violations: axe.Result[]) => void } & AxeOptions


SnapshotOptions

Ƭ SnapshotOptions: { dataTestID?: string ; index?: number } & CypressImageSnapshotOptions


StubbedInstance

Ƭ StubbedInstance<T>: GenericStubbedInstance<T, SinonStub>

Type parameters

Name
T

Functions

match

match(value): SinonMatcher

Sinon matcher for stubs/spy comparison

Parameters

Name Type
value number

Returns

SinonMatcher

Example

  // partial match of spy function params called with
  let { given, when, get } = new CypressHelper();
  it("should partially match spy params", () => {
      const obj = {
        func: (param: Object) => {}
      };
      given.spyOnObject(obj, "func");
      obj.func({ shelly: "go", inner: { attr: "value" } });
      then(get.spyFromFunction(obj.func)).shouldHaveBeenCalledWithMatch(
        match({ inner: { attr: "value" } })
      );
    });
For more information see Sinon.match documentation

match(value): SinonMatcher

Sinon matcher for stubs/spy comparison

Parameters

Name Type
value string

Returns

SinonMatcher

Example

  // partial match of spy function params called with
  let { given, when, get } = new CypressHelper();
  it("should partially match spy params", () => {
      const obj = {
        func: (param: Object) => {}
      };
      given.spyOnObject(obj, "func");
      obj.func({ shelly: "go", inner: { attr: "value" } });
      then(get.spyFromFunction(obj.func)).shouldHaveBeenCalledWithMatch(
        match({ inner: { attr: "value" } })
      );
    });
For more information see Sinon.match documentation

match(expr): SinonMatcher

Sinon matcher for stubs/spy comparison

Parameters

Name Type
expr RegExp

Returns

SinonMatcher

Example

  // partial match of spy function params called with
  let { given, when, get } = new CypressHelper();
  it("should partially match spy params", () => {
      const obj = {
        func: (param: Object) => {}
      };
      given.spyOnObject(obj, "func");
      obj.func({ shelly: "go", inner: { attr: "value" } });
      then(get.spyFromFunction(obj.func)).shouldHaveBeenCalledWithMatch(
        match({ inner: { attr: "value" } })
      );
    });
For more information see Sinon.match documentation

match(callback, message?): SinonMatcher

Sinon matcher for stubs/spy comparison

Parameters

Name Type
callback (value: any) => boolean
message? string

Returns

SinonMatcher

Example

  // partial match of spy function params called with
  let { given, when, get } = new CypressHelper();
  it("should partially match spy params", () => {
      const obj = {
        func: (param: Object) => {}
      };
      given.spyOnObject(obj, "func");
      obj.func({ shelly: "go", inner: { attr: "value" } });
      then(get.spyFromFunction(obj.func)).shouldHaveBeenCalledWithMatch(
        match({ inner: { attr: "value" } })
      );
    });
For more information see Sinon.match documentation

match(obj): SinonMatcher

Sinon matcher for stubs/spy comparison

Parameters

Name Type
obj object

Returns

SinonMatcher

Example

  // partial match of spy function params called with
  let { given, when, get } = new CypressHelper();
  it("should partially match spy params", () => {
      const obj = {
        func: (param: Object) => {}
      };
      given.spyOnObject(obj, "func");
      obj.func({ shelly: "go", inner: { attr: "value" } });
      then(get.spyFromFunction(obj.func)).shouldHaveBeenCalledWithMatch(
        match({ inner: { attr: "value" } })
      );
    });
For more information see Sinon.match documentation


then

then(subject): Assertable<unknown>

Wraps Cypress.Chainable and returns Assertable, decoupling test code form cypress 'should' assertions. This way you can add assertions of your own, by extending Assertable class.

Parameters

Name Type
subject any

Returns

Assertable<unknown>

Example

then(get.elementByTestId("selector")).shouldHaveLength(3)

Example

import { Assertable, then } from "@shellygo/cypress-test-utils/assertable";

class MyAssertable<T> extends Assertable<T> {
  private styleFromWindow = (win: Window) => {
    const styleItem = win.localStorage.getItem(`style`);
    const obj = JSON.parse(styleItem || "");
    return obj;
  };
  public shouldEqualToStoredStyle = () =>
    then(
      new CypressHelper().get.window().then((win) => {
         const style = styleFromWindow(win);
         then(this.chainable).shouldDeepNestedInclude(style);
      })
    );
}

class Driver {
 public given = {
   // methods for setting test pre-conditions
 };
 public when = {
   // methods for test "actions", such as click, darg & drop, etc.
 };
 public get = {
   // getter, for exploring the outcome, such as getting a text color a span
 };
 public then = (chainable: Cypress.Chainable<any>) => new MyAssertable(chainable);
}