cases
Advanced tools
Comparing version 0.1.1 to 1.0.0
'use strict'; | ||
var async = require('async'); | ||
const async = require('async'); | ||
var cases = function (data, fn) { | ||
const cases = function (data, fn) { | ||
if (typeof data === 'function') { | ||
@@ -10,11 +10,11 @@ return cases(data(), fn); | ||
var isAsync = (data[0].length !== fn.length); | ||
const isAsync = data[0].length !== fn.length; | ||
if (isAsync) { | ||
return function (done) { | ||
async.eachSeries(data, function (values, callback) { | ||
fn.apply(null, values.concat(callback)); | ||
}, function () { | ||
async.eachSeries(data, (values, callback) => { | ||
fn(...values.concat(callback)); | ||
}, () => { | ||
if (done) { | ||
done(); | ||
return done(); | ||
} | ||
@@ -26,5 +26,4 @@ }); | ||
return function () { | ||
var i; | ||
for (i = 0; i < data.length; i++) { | ||
fn.apply(null, data[i]); | ||
for (let i = 0; i < data.length; i++) { | ||
fn(...data[i]); | ||
} | ||
@@ -31,0 +30,0 @@ }; |
{ | ||
"name": "cases", | ||
"version": "0.1.1", | ||
"version": "1.0.0", | ||
"description": "cases provides parameterized unit tests for Mocha.", | ||
@@ -9,12 +9,20 @@ "contributors": [ | ||
"email": "golo.roden@thenativeweb.io" | ||
}, | ||
{ | ||
"name": "Matthias Wagler", | ||
"email": "matthias.wagler@thenativeweb.io" | ||
}, | ||
{ | ||
"name": "Jan-Hendrik Grundhöfer", | ||
"email": "jan-hendrik.grundhoefer@thenativeweb.io" | ||
} | ||
], | ||
"main": "./lib/cases.js", | ||
"main": "dist/cases.js", | ||
"dependencies": { | ||
"async": "0.9.0" | ||
"async": "2.6.0" | ||
}, | ||
"devDependencies": { | ||
"grunt": "0.4.5", | ||
"node-assertthat": "0.2.0", | ||
"tourism": "0.1.0" | ||
"assertthat": "1.0.0", | ||
"roboter": "0.15.6", | ||
"roboter-server": "0.15.6" | ||
}, | ||
@@ -28,3 +36,8 @@ "scripts": { | ||
}, | ||
"keywords": [ | ||
"mocha", | ||
"tdd", | ||
"test" | ||
], | ||
"license": "MIT" | ||
} |
@@ -7,3 +7,5 @@ # cases | ||
$ npm install cases | ||
```shell | ||
$ npm install cases | ||
``` | ||
@@ -15,6 +17,6 @@ ## Quick Start | ||
```javascript | ||
var cases = require('cases'); | ||
const cases = require('cases'); | ||
``` | ||
Now you can write your tests using Mocha as usual, but you may introduce cases for tests where you need multiple test cases. | ||
Now you can write your tests using Mocha as usual, but you may introduce cases for tests where you need multiple test cases: | ||
@@ -25,9 +27,10 @@ ```javascript | ||
[ 12, 17, 29 ] | ||
], function (first, second, expected) { | ||
var actual = add(first, second); | ||
assert.that(actual, is.equalTo(expected)); | ||
], (first, second, expected) => { | ||
const actual = add(first, second); | ||
assert.that(actual).is.equalTo(expected); | ||
})); | ||
``` | ||
This also works with asynchronous tests. The only difference is that you additionally need to provide the `done` parameter to your test function. | ||
This also works with asynchronous tests. The only difference is that you additionally need to provide the `done` parameter to your test function: | ||
@@ -38,5 +41,5 @@ ```javascript | ||
[ 12, 17, 29 ] | ||
], function (first, second, expected, done) { | ||
addAsync(first, second, function (actual) { | ||
assert.that(actual, is.equalTo(expected)); | ||
], (first, second, expected, done) => { | ||
addAsync(first, second, actual => { | ||
assert.that(actual).is.equalTo(expected); | ||
done(); | ||
@@ -49,6 +52,6 @@ }); | ||
Instead of providing all the test cases as inline data, you can alternatively specify a function that returns the test cases. This way you can load your test data from a file, a database or any other data source. | ||
Instead of providing all the test cases as inline data, you can alternatively specify a function that returns the test cases. This way you can load your test data from a file, a database or any other data source: | ||
```javascript | ||
test('add returns the sum.', cases(function () { | ||
test('add returns the sum.', cases(() => { | ||
return [ | ||
@@ -58,12 +61,13 @@ [ 23, 42, 65 ], | ||
]; | ||
}, function (first, second, expected) { | ||
var actual = add(first, second); | ||
assert.that(actual, is.equalTo(expected)); | ||
}, (first, second, expected) => { | ||
const actual = add(first, second); | ||
assert.that(actual).is.equalTo(expected); | ||
})); | ||
``` | ||
This also works for asynchronous test functions. Please note that the function that gets the test cases must be synchronous nevertheless. | ||
This also works for asynchronous test functions. Please note that the function that gets the test cases must be synchronous nevertheless: | ||
```javascript | ||
test('add returns the sum.', cases(function () { | ||
test('add returns the sum.', cases(() => { | ||
return [ | ||
@@ -73,5 +77,5 @@ [ 23, 42, 65 ], | ||
]; | ||
}, function (first, second, expected, done) { | ||
addAsync(first, second, function (actual) { | ||
assert.that(actual, is.equalTo(expected)); | ||
}, (first, second, expected, done) => { | ||
addAsync(first, second, actual => { | ||
assert.that(actual).is.equalTo(expected); | ||
done(); | ||
@@ -84,5 +88,7 @@ }); | ||
This module can be built using [Grunt](http://gruntjs.com/). Besides running the tests, this also analyses the code. To run Grunt, go to the folder where you have installed cases and run `grunt`. You need to have [grunt-cli](https://github.com/gruntjs/grunt-cli) installed. | ||
To build this module use [roboter](https://www.npmjs.com/package/roboter). | ||
$ grunt | ||
```shell | ||
$ bot | ||
``` | ||
@@ -92,3 +98,3 @@ ## License | ||
The MIT License (MIT) | ||
Copyright (c) 2013-2014 the native web. | ||
Copyright (c) 2013-2018 the native web. | ||
@@ -95,0 +101,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
11077
251
1
97
1
+ Addedasync@2.6.0(transitive)
+ Addedlodash@4.17.21(transitive)
- Removedasync@0.9.0(transitive)
Updatedasync@2.6.0