jest-each
Advanced tools
Comparing version 23.0.1 to 23.0.2
@@ -48,2 +48,3 @@ 'use strict'; | ||
const RECEIVED_COLOR = (_chalk || _load_chalk()).default.red; | ||
const SUPPORTED_PLACEHOLDERS = /%[sdifjoO%]/g; | ||
@@ -60,9 +61,11 @@ exports.default = cb => | ||
return (title, test) => { | ||
return function eachBind(title, test) { | ||
if (args.length === 1) { | ||
const table = args[0]; | ||
const table = args[0].every(Array.isArray) | ||
? args[0] | ||
: args[0].map(entry => [entry]); | ||
return table.forEach(row => | ||
cb( | ||
(_util || _load_util()).default.format.apply( | ||
(_util || _load_util()).default, | ||
arrayFormat.apply( | ||
undefined, | ||
[title].concat(_toConsumableArray(row)) | ||
@@ -82,16 +85,22 @@ ), | ||
if (data.length % keys.length !== 0) { | ||
const error = new Error( | ||
'Not enough arguments supplied for given headings:\n' + | ||
EXPECTED_COLOR(keys.join(' | ')) + | ||
'\n\n' + | ||
'Received:\n' + | ||
RECEIVED_COLOR( | ||
(0, (_prettyFormat || _load_prettyFormat()).default)(data) | ||
) + | ||
'\n\n' + | ||
`Missing ${RECEIVED_COLOR( | ||
`${data.length % keys.length}` | ||
)} arguments` | ||
); | ||
if (Error.captureStackTrace) { | ||
Error.captureStackTrace(error, eachBind); | ||
} | ||
return cb(title, () => { | ||
throw new Error( | ||
'Not enough arguments supplied for given headings:\n' + | ||
EXPECTED_COLOR(keys.join(' | ')) + | ||
'\n\n' + | ||
'Received:\n' + | ||
RECEIVED_COLOR( | ||
(0, (_prettyFormat || _load_prettyFormat()).default)(data) | ||
) + | ||
'\n\n' + | ||
`Missing ${RECEIVED_COLOR( | ||
`${data.length % keys.length}` | ||
)} arguments` | ||
); | ||
throw error; | ||
}); | ||
@@ -106,2 +115,20 @@ } | ||
const arrayFormat = function(str) { | ||
for ( | ||
var _len2 = arguments.length, | ||
args = Array(_len2 > 1 ? _len2 - 1 : 0), | ||
_key2 = 1; | ||
_key2 < _len2; | ||
_key2++ | ||
) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
} | ||
const matches = (str.match(SUPPORTED_PLACEHOLDERS) || []).length; | ||
return (_util || _load_util()).default.format.apply( | ||
(_util || _load_util()).default, | ||
[str].concat(_toConsumableArray(args.slice(0, matches))) | ||
); | ||
}; | ||
const applyRestParams = (params, test) => { | ||
@@ -108,0 +135,0 @@ if (params.length < test.length) |
@@ -14,30 +14,100 @@ 'use strict'; | ||
var _array; | ||
function _load_array() { | ||
return (_array = _interopRequireDefault(require('./array'))); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
var _template; | ||
const install = function(g) { | ||
for ( | ||
var _len = arguments.length, | ||
args = Array(_len > 1 ? _len - 1 : 0), | ||
_key = 1; | ||
_key < _len; | ||
_key++ | ||
) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
function _load_template() { | ||
return (_template = _interopRequireDefault(require('./template'))); | ||
} | ||
const test = (title, test) => | ||
(0, (_bind || _load_bind()).default)(g.test).apply(undefined, args)( | ||
title, | ||
test | ||
); | ||
test.skip = (0, (_bind || _load_bind()).default)(g.test.skip).apply( | ||
undefined, | ||
args | ||
); | ||
test.only = (0, (_bind || _load_bind()).default)(g.test.only).apply( | ||
undefined, | ||
args | ||
); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
const it = (title, test) => | ||
(0, (_bind || _load_bind()).default)(g.it).apply(undefined, args)( | ||
title, | ||
test | ||
); | ||
it.skip = (0, (_bind || _load_bind()).default)(g.it.skip).apply( | ||
undefined, | ||
args | ||
); | ||
it.only = (0, (_bind || _load_bind()).default)(g.it.only).apply( | ||
undefined, | ||
args | ||
); | ||
const xit = (0, (_bind || _load_bind()).default)(g.xit).apply( | ||
undefined, | ||
args | ||
); | ||
const fit = (0, (_bind || _load_bind()).default)(g.fit).apply( | ||
undefined, | ||
args | ||
); | ||
const xtest = (0, (_bind || _load_bind()).default)(g.xtest).apply( | ||
undefined, | ||
args | ||
); | ||
const describe = (title, suite) => | ||
(0, (_bind || _load_bind()).default)(g.describe).apply(undefined, args)( | ||
title, | ||
suite | ||
); | ||
describe.skip = (0, (_bind || _load_bind()).default)(g.describe.skip).apply( | ||
undefined, | ||
args | ||
); | ||
describe.only = (0, (_bind || _load_bind()).default)(g.describe.only).apply( | ||
undefined, | ||
args | ||
); | ||
const fdescribe = (0, (_bind || _load_bind()).default)(g.fdescribe).apply( | ||
undefined, | ||
args | ||
); | ||
const xdescribe = (0, (_bind || _load_bind()).default)(g.xdescribe).apply( | ||
undefined, | ||
args | ||
); | ||
return {describe, fdescribe, fit, it, test, xdescribe, xit, xtest}; | ||
}; /** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* | ||
*/ | ||
const each = function() { | ||
if (arguments.length > 1) { | ||
return (0, (_template || _load_template()).default)(global).apply( | ||
undefined, | ||
arguments | ||
); | ||
for ( | ||
var _len2 = arguments.length, args = Array(_len2), _key2 = 0; | ||
_key2 < _len2; | ||
_key2++ | ||
) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
return (0, (_array || _load_array()).default)(global).apply( | ||
undefined, | ||
arguments | ||
); | ||
return install.apply(undefined, [global].concat(args)); | ||
}; | ||
@@ -47,13 +117,11 @@ | ||
function() { | ||
if (arguments.length > 1) { | ||
return (0, (_template || _load_template()).default)(g).apply( | ||
undefined, | ||
arguments | ||
); | ||
for ( | ||
var _len3 = arguments.length, args = Array(_len3), _key3 = 0; | ||
_key3 < _len3; | ||
_key3++ | ||
) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
return (0, (_array || _load_array()).default)(g).apply( | ||
undefined, | ||
arguments | ||
); | ||
return install.apply(undefined, [g].concat(args)); | ||
}; | ||
@@ -60,0 +128,0 @@ |
{ | ||
"name": "jest-each", | ||
"version": "23.0.1", | ||
"version": "23.0.2", | ||
"description": "Parameterised tests for Jest", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -28,3 +28,10 @@ <div align="center"> | ||
* Asynchronous tests with `done` | ||
* Unique test titles with: [sprintf](https://github.com/alexei/sprintf.js) | ||
* 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) | ||
@@ -76,3 +83,5 @@ | ||
import each from 'jest-each'; | ||
``` | ||
```js | ||
// es5 | ||
@@ -94,3 +103,11 @@ const each = require('jest-each'); | ||
* name: `String` the title of the `test`, use `%s` in the name string to positionally inject parameter values into the test title | ||
* 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 | ||
@@ -106,3 +123,11 @@ | ||
* name: `String` the title of the `describe`, use `%s` in the name string to positionally inject parameter values into the suite title | ||
* 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 | ||
@@ -118,3 +143,3 @@ | ||
each([[1, 1, 2], [1, 2, 3], [2, 1, 3]]).test( | ||
'returns the result of adding %s to %s', | ||
'returns the result of adding %d to %d', | ||
(a, b, expected) => { | ||
@@ -132,3 +157,3 @@ expect(a + b).toBe(expected); | ||
each([[1, 1, 2], [1, 2, 3], [2, 1, 3]]).test.only( | ||
'returns the result of adding %s to %s', | ||
'returns the result of adding %d to %d', | ||
(a, b, expected) => { | ||
@@ -146,3 +171,3 @@ expect(a + b).toBe(expected); | ||
each([[1, 1, 2][(1, 2, 3)], [2, 1, 3]]).test.skip( | ||
'returns the result of adding %s to %s', | ||
'returns the result of adding %d to %d', | ||
(a, b, expected) => { | ||
@@ -160,3 +185,3 @@ expect(a + b).toBe(expected); | ||
each([['hello'], ['mr'], ['spy']]).test( | ||
'gives 007 secret message ', | ||
'gives 007 secret message: %s', | ||
(str, done) => { | ||
@@ -176,3 +201,3 @@ const asynchronousSpy = message => { | ||
each([[1, 1, 2], [1, 2, 3], [2, 1, 3]]).describe( | ||
'.add(%s, %s)', | ||
'.add(%d, %d)', | ||
(a, b, expected) => { | ||
@@ -202,3 +227,3 @@ test(`returns ${expected}`, () => { | ||
each([[1, 1, 2], [1, 2, 3], [2, 1, 3]]).describe.only( | ||
'.add(%s, %s)', | ||
'.add(%d, %d)', | ||
(a, b, expected) => { | ||
@@ -218,3 +243,3 @@ test(`returns ${expected}`, () => { | ||
each([[1, 1, 2], [1, 2, 3], [2, 1, 3]]).describe.skip( | ||
'.add(%s, %s)', | ||
'.add(%d, %d)', | ||
(a, b, expected) => { | ||
@@ -221,0 +246,0 @@ test(`returns ${expected}`, () => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
434
1
17708
4
246