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 23.1.0 to 23.2.0

100

build/bind.js

@@ -29,2 +29,6 @@ 'use strict';

function _toArray(arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
}
function _toConsumableArray(arr) {

@@ -38,3 +42,4 @@ if (Array.isArray(arr)) {

}
} /**
}
/**
* Copyright (c) 2018-present, Facebook, Inc. All rights reserved.

@@ -50,3 +55,4 @@ *

const RECEIVED_COLOR = (_chalk || _load_chalk()).default.red;
const SUPPORTED_PLACEHOLDERS = /%[sdifjoO%]/g;
const SUPPORTED_PLACEHOLDERS = /%[sdifjoOp%]/g;
const PRETTY_PLACEHOLDER = '%p';

@@ -85,3 +91,5 @@ exports.default = cb =>

if (data.length % keys.length !== 0) {
const missingData = data.length % keys.length;
if (missingData > 0) {
const error = new Error(

@@ -96,5 +104,6 @@ 'Not enough arguments supplied for given headings:\n' +

'\n\n' +
`Missing ${RECEIVED_COLOR(
`${data.length % keys.length}`
)} arguments`
`Missing ${RECEIVED_COLOR(missingData.toString())} ${pluralize(
'argument',
missingData
)}`
);

@@ -117,3 +126,10 @@

const arrayFormat = function(str) {
const getPrettyIndexes = placeholders =>
placeholders.reduce(
(indexes, placeholder, index) =>
placeholder === PRETTY_PLACEHOLDER ? indexes.concat(index) : indexes,
[]
);
const arrayFormat = function(title) {
for (

@@ -129,6 +145,38 @@ var _len2 = arguments.length,

const matches = (str.match(SUPPORTED_PLACEHOLDERS) || []).length;
const placeholders = title.match(SUPPORTED_PLACEHOLDERS) || [];
const prettyIndexes = getPrettyIndexes(placeholders);
var _args$reduce = args.reduce(
(acc, arg, index) => {
if (prettyIndexes.indexOf(index) !== -1) {
return {
args: acc.args,
title: acc.title.replace(
PRETTY_PLACEHOLDER,
(0, (_prettyFormat || _load_prettyFormat()).default)(arg, {
maxDepth: 1,
min: true
})
)
};
}
return {
args: acc.args.concat([arg]),
title: acc.title
};
},
{args: [], title}
);
const prettyTitle = _args$reduce.title,
remainingArgs = _args$reduce.args;
return (_util || _load_util()).default.format.apply(
(_util || _load_util()).default,
[str].concat(_toConsumableArray(args.slice(0, matches)))
[prettyTitle].concat(
_toConsumableArray(
remainingArgs.slice(0, placeholders.length - prettyIndexes.length)
)
)
);

@@ -157,8 +205,22 @@ };

const interpolate = (title, data) =>
Object.keys(data).reduce(
(acc, key) => acc.replace('$' + key, data[key]),
title
const getMatchingKeyPaths = title => (matches, key) =>
matches.concat(title.match(new RegExp(`\\$${key}[\\.\\w]*`, 'g')) || []);
const replaceKeyPathWithValue = data => (title, match) => {
const keyPath = match.replace('$', '').split('.');
const value = getPath(data, keyPath);
return title.replace(
match,
(0, (_prettyFormat || _load_prettyFormat()).default)(value, {
maxDepth: 1,
min: true
})
);
};
const interpolate = (title, data) =>
Object.keys(data)
.reduce(getMatchingKeyPaths(title), []) // aka flatMap
.reduce(replaceKeyPathWithValue(data), title);
const applyObjectParams = (obj, test) => {

@@ -169,1 +231,13 @@ if (test.length > 1) return done => test(obj, done);

};
const pluralize = (word, count) => word + (count === 1 ? '' : 's');
const getPath = (o, _ref) => {
var _ref2 = _toArray(_ref);
let head = _ref2[0],
tail = _ref2.slice(1);
if (!head || !o.hasOwnProperty || !o.hasOwnProperty(head)) return o;
return getPath(o[head], tail);
};

3

build/index.js

@@ -93,3 +93,4 @@ 'use strict';

return {describe, fdescribe, fit, it, test, xdescribe, xit, xtest};
}; /**
};
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.

@@ -96,0 +97,0 @@ *

{
"name": "jest-each",
"version": "23.1.0",
"version": "23.2.0",
"description": "Parameterised tests for Jest",

@@ -20,4 +20,4 @@ "main": "build/index.js",

"chalk": "^2.0.1",
"pretty-format": "^23.0.1"
"pretty-format": "^23.2.0"
}
}

@@ -16,34 +16,35 @@ <div align="center">

* `.test` to runs multiple tests with parameterised data
* Also under the alias: `.it`
* `.test.only` to only run the parameterised tests
* Also under the aliases: `.it.only` or `.fit`
* `.test.skip` to skip the parameterised tests
* 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`
* Unique test titles with [`printf` formatting](https://nodejs.org/api/util.html#util_util_format_format_args):
* `%s`- String.
* `%d`- Number.
* `%i` - Integer.
* `%f` - Floating point value.
* `%j` - JSON.
* `%o` - Object.
* `%%` - single percent sign ('%'). This does not consume an argument.
* 🖖 Spock like data tables with [Tagged Template Literals](#tagged-template-literal-of-rows)
- `.test` to runs multiple tests with parameterised data
- Also under the alias: `.it`
- `.test.only` to only run the parameterised tests
- Also under the aliases: `.it.only` or `.fit`
- `.test.skip` to skip the parameterised tests
- 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`
- Unique test titles with [`printf` formatting](https://nodejs.org/api/util.html#util_util_format_format_args):
- `%p` - [pretty-format](https://www.npmjs.com/package/pretty-format).
- `%s`- String.
- `%d`- Number.
- `%i` - Integer.
- `%f` - Floating point value.
- `%j` - JSON.
- `%o` - Object.
- `%%` - single percent sign ('%'). This does not consume an argument.
- 🖖 Spock like data tables with [Tagged Template Literals](#tagged-template-literal-of-rows)
---
* [Demo](#demo)
* [Installation](#installation)
* [Importing](#importing)
* APIs
* [Array of Rows](#array-of-rows)
* [Usage](#usage)
* [Tagged Template Literal of rows](#tagged-template-literal-of-rows)
* [Usage](#usage-1)
- [Demo](#demo)
- [Installation](#installation)
- [Importing](#importing)
- APIs
- [Array of Rows](#array-of-rows)
- [Usage](#usage)
- [Tagged Template Literal of rows](#tagged-template-literal-of-rows)
- [Usage](#usage-1)

@@ -98,16 +99,18 @@ ## Demo

* parameters: `Array` of Arrays with the arguments that are passed into the `testFn` for each row
- parameters: `Array` of Arrays with the arguments that are passed into the `testFn` for each row
- _Note_ If you pass in a 1D array of primitives, internally it will be mapped to a table i.e. `[1, 2, 3] -> [[1], [2], [3]]`
##### `.test`:
* name: `String` the title of the `test`.
* Generate unique test titles by positionally injecting parameters with [`printf` formatting](https://nodejs.org/api/util.html#util_util_format_format_args):
* `%s`- String.
* `%d`- Number.
* `%i` - Integer.
* `%f` - Floating point value.
* `%j` - JSON.
* `%o` - Object.
* `%%` - single percent sign ('%'). This does not consume an argument.
* testFn: `Function` the test logic, this is the function that will receive the parameters of each row as function arguments
- name: `String` the title of the `test`.
- Generate unique test titles by positionally injecting parameters with [`printf` formatting](https://nodejs.org/api/util.html#util_util_format_format_args):
- `%p` - [pretty-format](https://www.npmjs.com/package/pretty-format).
- `%s`- String.
- `%d`- Number.
- `%i` - Integer.
- `%f` - Floating point value.
- `%j` - JSON.
- `%o` - Object.
- `%%` - single percent sign ('%'). This does not consume an argument.
- testFn: `Function` the test logic, this is the function that will receive the parameters of each row as function arguments

@@ -118,16 +121,18 @@ #### `each([parameters]).describe(name, suiteFn)`

* parameters: `Array` of Arrays with the arguments that are passed into the `suiteFn` for each row
- parameters: `Array` of Arrays with the arguments that are passed into the `suiteFn` for each row
- _Note_ If you pass in a 1D array of primitives, internally it will be mapped to a table i.e. `[1, 2, 3] -> [[1], [2], [3]]`
##### `.describe`:
* name: `String` the title of the `describe`
* Generate unique test titles by positionally injecting parameters with [`printf` formatting](https://nodejs.org/api/util.html#util_util_format_format_args):
* `%s`- String.
* `%d`- Number.
* `%i` - Integer.
* `%f` - Floating point value.
* `%j` - JSON.
* `%o` - Object.
* `%%` - single percent sign ('%'). This does not consume an argument.
* 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
- name: `String` the title of the `describe`
- Generate unique test titles by positionally injecting parameters with [`printf` formatting](https://nodejs.org/api/util.html#util_util_format_format_args):
- `%p` - [pretty-format](https://www.npmjs.com/package/pretty-format).
- `%s`- String.
- `%d`- Number.
- `%i` - Integer.
- `%f` - Floating point value.
- `%j` - JSON.
- `%o` - Object.
- `%%` - single percent sign ('%'). This does not consume an argument.
- 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

@@ -266,9 +271,10 @@ ### Usage

* First row of variable name column headings seperated with `|`
* One or more subsequent rows of data supplied as template literal expressions using `${value}` syntax.
- First row of variable name column headings seperated with `|`
- One or more subsequent rows of data supplied as template literal expressions using `${value}` syntax.
##### `.test`:
* name: `String` the title of the `test`, use `$variable` in the name string to inject test values into the test title from the tagged template expressions
* testFn: `Function` the test logic, this is the function that will receive the parameters of each row as function arguments
- name: `String` the title of the `test`, use `$variable` in the name string to inject test values into the test title from the tagged template expressions
- To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value`
- testFn: `Function` the test logic, this is the function that will receive the parameters of each row as function arguments

@@ -302,9 +308,10 @@ #### `each[tagged template].describe(name, suiteFn)`

* First row of variable name column headings seperated with `|`
* One or more subsequent rows of data supplied as template literal expressions using `${value}` syntax.
- First row of variable name column headings seperated with `|`
- One or more subsequent rows of data supplied as template literal expressions using `${value}` syntax.
##### `.describe`:
* name: `String` the title of the `test`, use `$variable` in the name string to inject test values into the test title from the tagged template expressions
* 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
- name: `String` the title of the `test`, use `$variable` in the name string to inject test values into the test title from the tagged template expressions
- To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value`
- 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

@@ -311,0 +318,0 @@ ### Usage

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