Socket
Socket
Sign inDemoInstall

jest-each

Package Overview
Dependencies
Maintainers
1
Versions
144
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-each - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

42

dist/index.js

@@ -35,24 +35,36 @@ (function (global, factory) {

var tests = parameterisedTests(parameterRows);
var globalTest = defaultGlobal.test;
var test = parameterisedTests(parameterRows, globalTest);
test.skip = parameterisedTests(parameterRows, globalTest.skip);
test.only = parameterisedTests(parameterRows, globalTest.only);
var test = tests(globalTest);
test.skip = tests(globalTest.skip);
test.only = tests(globalTest.only);
var globalIt = defaultGlobal.it;
var it = parameterisedTests(parameterRows, globalIt);
it.skip = parameterisedTests(parameterRows, globalIt.skip);
it.only = parameterisedTests(parameterRows, globalIt.only);
var it = tests(globalIt);
it.skip = tests(globalIt.skip);
it.only = tests(globalIt.only);
var xtest = parameterisedTests(parameterRows, defaultGlobal.xtest);
var xit = parameterisedTests(parameterRows, defaultGlobal.xit);
var fit = parameterisedTests(parameterRows, defaultGlobal.fit);
var xtest = tests(defaultGlobal.xtest);
var xit = tests(defaultGlobal.xit);
var fit = tests(defaultGlobal.fit);
return { test: test, xtest: xtest, it: it, xit: xit, fit: fit };
var globalDescribe = defaultGlobal.describe;
var describe = tests(globalDescribe);
describe.skip = tests(globalDescribe.skip);
describe.only = tests(globalDescribe.only);
var fdescribe = tests(defaultGlobal.fdescribe);
var xdescribe = tests(defaultGlobal.xdescribe);
return { test: test, xtest: xtest, it: it, xit: xit, fit: fit, describe: describe, fdescribe: fdescribe, xdescribe: xdescribe };
};
var parameterisedTests = function parameterisedTests(parameterRows, globalCb) {
return function (title, test) {
parameterRows.forEach(function (params) {
return globalCb((0, _sprintfJs.vsprintf)(title, params), applyTestParams(params, test));
});
var parameterisedTests = function parameterisedTests(parameterRows) {
return function (globalCb) {
return function (title, test) {
parameterRows.forEach(function (params) {
return globalCb((0, _sprintfJs.vsprintf)(title, params), applyTestParams(params, test));
});
};
};

@@ -59,0 +71,0 @@ };

{
"name": "jest-each",
"version": "0.2.0",
"version": "0.3.0",
"description": "Parameterised tests for Jest",

@@ -13,3 +13,3 @@ "main": "dist/index.js",

"prepublish": "npm run build",
"test": "jest",
"test": "jest --testPathPattern=src",
"test:coveralls": "npm run test:coverage && cat ./coverage/lcov.info | coveralls",

@@ -16,0 +16,0 @@ "test:coverage": "jest --coverage"

# jest-each
[![npm version](https://badge.fury.io/js/jest-each.svg)](https://badge.fury.io/js/jest-each)
[![Build Status](https://travis-ci.org/mattphillips/jest-each.svg?branch=master)](https://travis-ci.org/mattphillips/jest-each)

@@ -8,3 +9,3 @@ [![Coverage Status](https://coveralls.io/repos/github/mattphillips/jest-each/badge.svg?branch=master)](https://coveralls.io/github/mattphillips/jest-each?branch=master)

jest-each allows you to provide multiple arguments to your `test` which results in the test being run once per row of parameters.
jest-each allows you to provide multiple arguments to your `test`/`describe` which results in the test/suite being run once per row of parameters.

@@ -18,2 +19,7 @@ ## Features

* Also under the aliases: `.it.skip` or `.xit` or `.xtest`
- `.describe` to runs test suites with parameterised data
- `.describe.only` to only run the parameterised suite of tests
* Also under the aliases: `.fdescribe`
- `.describe.skip` to skip the parameterised suite of tests
* Also under the aliases: `.xdescribe`
- Asynchronous tests with `done`

@@ -42,11 +48,20 @@ - Unique test titles with: [sprintf](https://github.com/alexei/sprintf.js)

### `each([parameters]).test(name, fn)`
### `each([parameters]).test(name, testFn)`
#### `each`:
- parameters: `Array` the arguments that are passed into the `fn`
- parameters: `Array` of Arrays with the arguments that are passed into the `testFn` for each row
#### `.test`:
- name: `String` the title of the `test`, use `%s` in the name string to positionally inject parameter values into the test title
- fn: `Function` the test logic, this is the function that will receive the parameters as function arguments
- testFn: `Function` the test logic, this is the function that will receive the parameters of each row as function arguments
### `each([parameters]).describe(name, suiteFn)`
#### `each`:
- parameters: `Array` of Arrays with the arguments that are passed into the `suiteFn` for each row
#### `.describe`:
- name: `String` the title of the `describe`, use `%s` in the name string to positionally inject parameter values into the suite title
- suiteFn: `Function` the suite of `test`/`it`s to be ran, this is the function that will receive the parameters in each row as function arguments
## Usage

@@ -74,3 +89,7 @@

```js
each([ [1, 1, 2] ]).test.only('returns the result of adding %s to %s', (a, b, expected) => {
each([
[1, 1, 2],
[1, 2, 3],
[2, 1, 3],
]).test.only('returns the result of adding %s to %s', (a, b, expected) => {
expect(add(a, b)).toBe(expected);

@@ -84,3 +103,7 @@ });

```js
each([ [1, 1, 2] ]).test.skip('returns the result of adding %s to %s', (a, b, expected) => {
each([
[1, 1, 2]
[1, 2, 3],
[2, 1, 3],
]).test.skip('returns the result of adding %s to %s', (a, b, expected) => {
expect(add(a, b)).toBe(expected);

@@ -107,4 +130,61 @@ });

#### `.describe(name, fn)`
```js
import each from 'jest-each';
import add from './add';
each([
[1, 1, 2],
[1, 2, 3],
[2, 1, 3],
]).describe('.add(%s, %s)', (a, b, expected) => {
test(`returns ${expected}`, () => {
expect(add(a, b)).toBe(expected);
});
test('does not mutate first arg', () => {
add(a, b);
expect(a).toBe(a);
});
test('does not mutate second arg', () => {
add(a, b);
expect(b).toBe(b);
});
});
```
#### `.describe.only(name, fn)`
Aliases: `.fdescribe(name, fn)`
```js
each([
[1, 1, 2],
[1, 2, 3],
[2, 1, 3],
]).describe.only('.add(%s, %s)', (a, b, expected) => {
test(`returns ${expected}`, () => {
expect(add(a, b)).toBe(expected);
});
});
```
#### `.describe.skip(name, fn)`
Aliases: `.xdescribe(name, fn)`
```js
each([
[1, 1, 2],
[1, 2, 3],
[2, 1, 3],
]).describe.skip('.add(%s, %s)', (a, b, expected) => {
test(`returns ${expected}`, () => {
expect(add(a, b)).toBe(expected);
});
});
```
## License
MIT
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