1.0.11 • Published 4 years ago

testid-support v1.0.11

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

testid-support

testid support: props and selectors generator

Installation

npm i testid-support

Usage

In the environment with the app UI code (/app) and e2e test (/tests/e2e) there needs to be a shared folder (/shared). Then,

// shared/selectors.js
import { defineTestIdDictionary } from 'testid-support';

export const selectorsDictionary = defineTestIdDictionary((testId, testIdRest) => ({
  PAGE_LANDING: testId('page', 'landing'),
  INFO_CART_VALUE: testId('text', 'cart subtotal'),
  INFO_CART_VALUE_OF: testIdRest('text', 'cart subtotal'),
}));

Then, in the application code use:

// app/testIds.js

import { FOR_RENDER } from 'testid-support';
import { selectorsDictionary } from '../shared/selectors';

export const e2eAssist = selectorsDictionary(FOR_RENDER);
// tests/e2e/queries.js

import { FOR_TESTS } from 'testid-support';
import { selectorsDictionary } from '../../shared/selectors';

export const SEL = selectorsDictionary(FOR_TESTS);

Then, in the application code (React), use it like so:

<section { ...e2eAssist.PAGE_LANDING }>
  <div className="cart" { { ...e2eAssist.INFO_CART_VALUE_OF(cartTotal) } }>{ cartTotal }</div>
</section>

While in the tests, use the following counterparts to test for presence/select the proper elements:

const cartElement = await page.waitForSelector(
  `${ SEL.PAGE_LANDING } ${ SEL.INFO_CART_VALUE }`);
1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago