Detalhes do pacote

@jscutlery/cypress-harness

jscutlery18.8k0.8.5

The Background Story

readme (leia-me)

Cypress Harness

The Background Story

Both unit-testing and e2e testing can get tricky when it comes to interacting with the DOM. In fact, tests have to be decoupled from the implementation details of the code they test. Especially if you are interacting with same components of an app in different tests.

This often happens with UI libraries like Angular Material and that is why the Angular Material's team came up with the amazing idea of creating a testing abstraction layer over components called Component Test Harnesses.

One of the most interesting ideas behind Component Test Harnesses is that they are also meant to be platform agnostic, which means they can be used in your unit-tests with Jest or Karma, in your e2e tests with Protractor or Cypress or in your Cypress Component Tests.

This library provides Cypress support to Component Test Harnesses.

Angular Material Datepicker Harness in Cypress

Setup

1. Install

yarn add -D @jscutlery/cypress-harness @angular/cdk cypress-pipe

# or

npm install -D @jscutlery/cypress-harness @angular/cdk cypress-pipe

2. Setup

2.a. Cypress E2E

Update your e2e folder's cypress/support/e2e.ts and add:

import '@jscutlery/cypress-harness/support';

then update the cypress.config.ts file as follows:

import { defineConfig } from 'cypress';
import { getPreprocessorConfig } from '@jscutlery/cypress-harness/preprocessor-config';

export default defineConfig({
  e2e: {
    // ... other existing settings if any (like nxE2EPreset() if using Nx).
    ...getPreprocessorConfig(),
  },
});

This last part is needed to add support for package exports conditionals and allow us to import harnesses from @angular/cdk/testing for example.

2.b. Cypress Component Testing

If you are using Cypress Component Testing then there is a different import to add to the following file: cypress/support/component.ts:

import '@jscutlery/cypress-harness/support-ct';

(the getPreprocessorConfig() is not required here as it is already set up by cypress/angular.)

Usage

describe('datepicker', () => {
  /* getHarness & getAllHarnesses are lazy so you can
   * initialize them wherever you want and reuse them. */
  const datepicker = getHarness(MatDatepickerInputHarness);
  const calendars = getAllHarnesses(MatCalendarHarness);

  it('should set date', () => {
    cy.visit('/'); // or cy.mount(MyComponent); for component testing.
    datepicker.setValue('1/1/2010');
    datepicker.openCalendar();
    datepicker.getCalendar().then((harness) => harness.next()); // next method is already used
    datepicker.getCalendar().selectCell({ text: '10' });
    datepicker.getValue().should('equal', '2/10/2010');
    calendars.should('be.empty');
  });
});

changelog (log de mudanças)

0.8.5 (2025-05-31)

🩹 Fixes

  • 📦 update dependency @babel/core to v7.27.4 (#878)

0.8.4 (2025-05-29)

🩹 Fixes

  • 📦 update dependency @babel/core to v7.27.3 (#873)

0.8.3 (2025-05-24)

🩹 Fixes

  • 📦 update dependency zone.js to v0.15.1 (#868)

0.8.2 (2025-05-13)

🩹 Fixes

  • 📦 update dependency @babel/core to v7.27.1 (#856)

0.8.1 (2025-03-31)

🩹 Fixes

  • 📦 update dependency @babel/core to v7.26.10 (#804)

0.8.0 (2025-03-24)

🚀 Features

  • ✨ handle useDefineForClassFields option (#793)

❤️ Thank You

  • Younes Jaaidi @yjaaidi

0.7.22 (2025-02-28)

🩹 Fixes

  • 📦 update dependency rxjs to v7.8.2 (#788)

0.7.21 (2025-02-17)

🩹 Fixes

  • 📦 update dependency @babel/core to v7.26.9 (#772)

0.7.20 (2025-02-11)

🩹 Fixes

  • 📦 update dependency @babel/core to v7.26.8 (#762)

0.7.19 (2025-01-29)

🚀 Features

  • swc-angular: upgrade swc core version to support 1.10.x (3995b73)

🩹 Fixes

  • 📦 update dependency @babel/core to v7.26.7 (#746)

❤️ Thank You

  • Edouard Bozon

0.7.18 (2025-01-13)

🚀 Features

  • swc-angular-plugin: use new wasm32-wasip1 build target (d2a23a2)
  • swc-angular-plugin: add support for latest @swc/core (#674)

🩹 Fixes

  • 📦 update dependency @babel/helper-plugin-utils to v7.26.5 (#720)

❤️ Thank You

  • Dmitry Zakharov @pumano
  • Edouard Bozon @edbzn

0.7.17 (2024-11-08)

🩹 Fixes

  • 📦 update babel monorepo (#647)

0.7.16 (2024-11-04)

🩹 Fixes

  • 📦 update dependency tslib to v2.8.1 (#642)

0.7.15 (2024-10-31)

🩹 Fixes

  • 📦 update dependency tslib to v2.8.0 (#638)

❤️ Thank You

  • 56789a1987 @56789a1987
  • Edouard Bozon @edbzn
  • Younes Jaaidi @yjaaidi

0.7.14 (2024-10-14)

🩹 Fixes

  • 📦 update dependency @babel/core to v7.25.8 (#609)

❤️ Thank You

  • Dmitry Zakharov @pumano

0.7.13 (2024-10-09)

🩹 Fixes

  • 📦 update dependency @babel/core to v7.25.7 (#604)

❤️ Thank You

  • Younes Jaaidi @yjaaidi

0.7.12 (2024-08-25)

🩹 Fixes

  • 📦 update dependency tslib to v2.7.0 (#546)

0.7.11 (2024-08-24)

🩹 Fixes

  • 📦 update dependency zone.js to v0.15.0 (#544)

0.7.10 (2024-08-13)

🩹 Fixes

  • 📦 update dependency @babel/core to v7.25.2 (#527)

0.7.9 (2024-08-08)

🩹 Fixes

  • 📦 update dependency zone.js to v0.14.10 (#520)

0.7.8 (2024-07-23)

🩹 Fixes

  • 📦 update dependency @babel/core to v7.24.9 (#494)

0.7.7 (2024-07-23)

🩹 Fixes

  • 📦 update dependency zone.js to v0.14.8 (#495)

0.7.6 (2024-06-19)

🩹 Fixes

  • 📦 update dependency @babel/core to v7.24.7 (#452)

0.7.5 (2024-06-11)

🩹 Fixes

  • 📦 update dependency tslib to v2.6.3 (#441)

0.7.4 (2024-06-09)

🩹 Fixes

  • 📦 update dependency zone.js to v0.14.7 (#437)

❤️ Thank You

  • Younes Jaaidi @yjaaidi

0.7.3 (2024-05-21)

🩹 Fixes

  • 📦 update dependency @babel/core to v7.24.5 (#398)

0.7.2 (2024-05-19)

🩹 Fixes

  • 📦 update dependency zone.js to v0.14.6 (#396)

❤️ Thank You

  • Younes Jaaidi

0.7.1 (2024-05-13)

🩹 Fixes

  • 📦 update dependency zone.js to v0.14.5 (#377)

❤️ Thank You

  • Younes Jaaidi

0.6.0 (2024-04-12)

  • Nothing changed

0.5.2 (2024-03-22)

0.5.1 (2023-12-05)

Bug Fixes

  • import of zone.js and zone.js/testing (f14b091)

0.5.0 (2023-10-31)

Features

  • playwright-ct-angular: ✨ upgrade to playwright 1.39 support (#264) (4354d3e)

0.4.7 (2023-10-28)

0.4.6 (2023-10-25)

0.4.5 (2023-10-25)

0.4.5 (2023-10-25)

0.4.5 (2023-10-25)

0.4.5 (2023-10-25)

0.4.5 (2023-10-25)

0.4.4 (2023-05-24)

0.4.3 (2023-05-22)

Bug Fixes

0.4.2 (2022-12-03)

Bug Fixes

  • cypress-harness: 🐞 fix webpack import error (787219c)

0.4.1 (2022-12-01)

0.4.0 (2022-12-01)

Features

  • cypress-harness: ✨ provide getPreprocessorConfig util (56d74c9)
  • cypress-harness: ✨add support for Cypress 10 & 11 (4d29535)

0.3.12 (2022-06-24)

0.3.12 (2022-06-24)

0.3.12 (2022-06-24)

0.3.11 (2022-03-27)

Bug Fixes

  • 🐞 add missing peerDependencies (f820bad)
  • 🐞 bump workspace (127c808)

0.3.10 (2022-03-26)

0.3.9 (2021-12-08)

0.3.8 (2021-10-26)

0.3.7 (2021-10-25)

Bug Fixes

  • use standalone projects (8e4b7b7)

0.3.6 (2021-08-05)

Bug Fixes

  • cypress-harness: 🐞 fix getAllHarnesses type (e66d08c)

0.3.5 (2021-06-29)

Bug Fixes

  • cypress-harness: 🐞 correct return type of getAllHarnesses (7b99fd9)
  • cypress-harness: 🐞 fix typing with strict mode (8ff4b42)

0.3.4 (2021-05-15)

0.3.3 (2021-05-13)

0.3.2 (2021-02-25)

0.3.1 (2021-02-25)

0.3.0 (2021-02-25)

Bug Fixes

  • cypress-harness: 🐞 don't proxy native cypress functions (db3a409)

Features

  • cypress-harness: ✅ make getHarness & getAllHarnesses & getRootHarness harnesses reusable (35335a3), closes #3
  • cypress-harness: ✅ support first level method chaining (e52c26a)
  • cypress-harness: ✅ support recursive chaining (363ce84)

0.2.1 (2021-02-10)

Bug Fixes

  • cypress-harness: 🐞 support cypress-mount 0.5.0 (07877e5)

0.2.0 (2021-01-04)

Bug Fixes

  • cypress-harness: 🐞 fix "zone-testing is needed" error (ab7b5a0), closes #2
  • document root (a99cf73)

Features

  • cypress-harness: ✅ add @jscutlery/cypress-harness/support (454016d)
  • ✅ remove log (758c62a)
  • use UnitTestElement (79db9a0)
  • cypress-harness: ✅ add chainable typed methods to getHarness result (32f7e86)
  • cypress-harness: ✅ add chainable typed methods to getRootHarness result (7f2936d)
  • cypress-harness: ✅ add getRootHarness (27a1936)
  • cypress-harness: ✅ log harness method name (82c5744)

0.1.0 (2020-12-01)

Bug Fixes

Features

  • cypress-harness: ✅ add @jscutlery/cypress-harness/support (454016d)
  • ✅ remove log (758c62a)
  • use UnitTestElement (79db9a0)
  • cypress-harness: ✅ add chainable typed methods to getHarness result (32f7e86)
  • cypress-harness: ✅ add chainable typed methods to getRootHarness result (7f2936d)
  • cypress-harness: ✅ add getRootHarness (27a1936)
  • cypress-harness: ✅ log harness method name (82c5744)