@xtreamsrl/react-cypress
TypeScript icon, indicating that this package has built-in type declarations

0.1.5 • Public • Published

@xtreamsrl/react-cypress

This package exposes cypress E2E testing utilities.

Installation

npm install @xtreamsrl/react-cypress

Usage

The library provides some custom cypress commands:

  • getById: retrieves the element with the provided test id
  • containsTranslationOf: retrieves the element that contains the translation of the provided key
  • containsFormattedDate: retrieves the element that contains the date formatted with the provided format

And chai assertions:

  • translationOf: assertion for containing translated string
  • formattedDate: assertion for containing formatted date

In order to use the custom commands and assertions, it is necessary to expose I18n in the window object. To do it, add the following code to the App.tsx file:

if ((window as any).Cypress) {
  import('./cypressThings').then(module => module.makeCypressHappy());
}

The cypressThings file, or any name you prefer to assign to it, should contain the following code:

import { I18n } from 'i18n-js';
export function makeCypressHappy() {
  (window as any).i18n = I18n;
}

What happens is that when the application is running in the Cypress test environment, it dynamically imports cypressThings and invokes the function 'makeCypressHappy' from that module. This approach allows to include testing-specific functionality or configurations when running tests with Cypress.

Who we are

xtream logo

A proudly 🇮🇹 software development and data science startup.
We consider ourselves a family of talented and passionate people building their own products and powerful solutions for our clients. Get to know us more on xtreamers.io or follow us on LinkedIn.

Readme

Keywords

none

Package Sidebar

Install

npm i @xtreamsrl/react-cypress

Weekly Downloads

1

Version

0.1.5

License

none

Unpacked Size

57.9 kB

Total Files

8

Last publish

Collaborators

  • xtreamsrl