Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cypress-each

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cypress-each - npm Package Compare versions

Comparing version 1.5.0 to 1.6.0

6

package.json
{
"name": "cypress-each",
"version": "1.5.0",
"version": "1.6.0",
"description": "Simple implementation for describe.each and it.each",

@@ -19,4 +19,4 @@ "main": "src",

"devDependencies": {
"cypress": "8.6.0",
"cypress-expect": "2.4.3",
"cypress": "8.7.0",
"cypress-expect": "2.5.0",
"mocha-each": "^2.0.1",

@@ -23,0 +23,0 @@ "prettier": "^2.4.1",

@@ -1,2 +0,2 @@

# cypress-each ![cypress version](https://img.shields.io/badge/cypress-8.6.0-brightgreen) [![renovate-app badge][renovate-badge]][renovate-app] [![ci](https://github.com/bahmutov/cypress-each/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/bahmutov/cypress-each/actions/workflows/ci.yml)
# cypress-each ![cypress version](https://img.shields.io/badge/cypress-8.7.0-brightgreen) [![renovate-app badge][renovate-badge]][renovate-app] [![ci](https://github.com/bahmutov/cypress-each/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/bahmutov/cypress-each/actions/workflows/ci.yml)
> A demo of mocha-each and custom describe.each and it.each implementation for Cypress

@@ -9,2 +9,6 @@

## Videos
- Watch [Using cypress-each To Create Separate Tests](https://youtu.be/utPKRV_fL1E)
## Install and use

@@ -64,2 +68,21 @@

## Repeat the test N times
You can use this module to simply repeat the test N times
```js
// repeat the same test 5 times
it.each(5)('test %K of 5', function (k) {
// note the iteration index k is passed to each test
expect(k).to.be.within(0, 4)
})
// you can repeat the suite of tests
describe.each(3)('suite %K of 3', function (k) {
...
})
```
See the [repeat-spec.js](./cypress/integration/repeat-spec.js)
## Test and suite titles

@@ -143,7 +166,33 @@

## Examples
## Exclusive tests
- Watch [Using cypress-each To Create Separate Tests](https://youtu.be/utPKRV_fL1E)
- Read [Dynamic API Tests Using Cypress-Each Plugin](https://glebbahmutov.com/blog/dynamic-api-tests-using-cypress-each/)
Normally you could run just a selected test using `it.only` or a suite of tests using `describe.only`. Similarly, you could skip a single test or a suite of tests using `it.skip` and `describe.skip` methods. These methods are NOT supported by `it.each` and `describe.each`. Thus if you want to only run the `it.each` tests, surround it with its own `describe` block.
```js
// only run the generated tests
describe.only('my tests', () => {
it.each(items)(...)
})
// skip these tests
describe.skip('obsolete generated tests', () => {
it.each(items)(...)
})
// run just these suites of generated tests
describe.only('my suites of tests', () => {
describe.each(items)(...)
})
```
## Test configuration object
Cypress allows to pass some of its configuration options in the `it` and `describe` arguments, see [the configuration](https://on.cypress.io/configuration) page. These methods `it.each` and `describe.each` do not support this, but you can create a wrapper `describe` block and set the options there, if needed.
```js
// if a test inside this suite fails,
// retry it up to two times before failing it
describe('user', { retries: 2 }, () => {
it.each(users)(...)
})
```
## Specs

@@ -150,0 +199,0 @@

@@ -14,3 +14,3 @@ // types for it.each and describe.each

* a separate test for each one.
* @param values Input items to create the tests form
* @param values Input items to create the tests form OR number of times to repeat a test
* @param totalChunks (Optional) number of chunks to split the items into

@@ -22,3 +22,3 @@ * @param chunkIndex (Optional) index of the chunk to get items from

each<T = unknown>(
values: T[],
values: T[] | number,
totalChunks?: number,

@@ -40,3 +40,3 @@ chunkIndex?: number,

each<T = unknown>(
values: T[],
values: T[] | number,
totalChunks?: number,

@@ -43,0 +43,0 @@ chunkIndex?: number,

@@ -50,2 +50,10 @@ /// <reference types="cypress" />

it.each = function (values, totalChunks, chunkIndex) {
if (typeof values === 'number') {
// the user wants to repeat the same test N times
if (values < 1) {
throw new Error('Number of test repetitions must be >= 1')
}
values = Cypress._.range(0, values)
}
if (!Array.isArray(values)) {

@@ -89,2 +97,10 @@ throw new Error('cypress-each: values must be an array')

describe.each = function (values) {
if (typeof values === 'number') {
// the user wants to repeat the same suite N times
if (values < 1) {
throw new Error('Number of suite repetitions must be >= 1')
}
values = Cypress._.range(0, values)
}
if (!Array.isArray(values)) {

@@ -91,0 +107,0 @@ throw new Error('cypress-each: values must be an array')

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc