jest-theories
Advanced tools
Comparing version
@@ -23,4 +23,4 @@ 'use strict'; | ||
theories.forEach(function (theory) { | ||
test((0, _stringFormat2.default)(testName, theory), testFunc.bind(undefined, theory)); | ||
theories.forEach(function (theory, idx) { | ||
test((0, _stringFormat2.default)(testName, Object.assign({}, theory, { "$idx": idx, "$no": idx + 1 })), testFunc.bind(undefined, theory)); | ||
}); | ||
@@ -27,0 +27,0 @@ }; |
15
index.js
import format from 'string-format'; | ||
const theoretically = (testName, theories, testFunc) => { | ||
if(!test){ | ||
if (!test) { | ||
throw new Error('Jest test global must be accessible to use jest-theories'); | ||
} | ||
if(!Array.isArray(theories)){ | ||
throw new Error('Theories must be an array (was '+ typeof theories + ')'); | ||
if (!Array.isArray(theories)) { | ||
throw new Error('Theories must be an array (was ' + typeof theories + ')'); | ||
} | ||
theories.forEach(theory => { | ||
test(format(testName, theory), testFunc.bind(this, theory)); | ||
theories.forEach((theory, idx) => { | ||
test( | ||
format(testName, Object.assign({}, theory, { "$idx": idx, "$no": idx + 1 })), | ||
testFunc.bind(this, theory) | ||
); | ||
}); | ||
@@ -14,0 +17,0 @@ }; |
{ | ||
"name": "jest-theories", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "build": "babel index.js --out-dir dist" |
@@ -29,5 +29,7 @@ # jest-theories | ||
Additionally to the fields available in your theory you can also use `$idx` for the index of the theory and `$no` for the number of the theory. | ||
## Inspiration | ||
Inspiration from [jasmine-theories](https://github.com/hypesystem/jasmine-theories) and XUnit. |
4979
6.43%42
7.69%35
6.06%