forked from fluentforward/data-driven
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (42 loc) · 1.24 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*!
* data-driven
* Copyright(c) 2013 Fluent Software Solutions Ltd <[email protected]>
* MIT Licensed
*/
module.exports = function(data, fn) {
var mochaIt = it
var mochaBefore = before
data.forEach(function(testData) {
try {
it = function(title, f) {
for (var key in testData) {
title = title.replace('{'+key+'}',testData[key])
}
if (f !== undefined) {
var testFn = f.length < 2 ?
function() {
f.call(this,testData)
} :
function(done) {
f.call(this,testData,done)
}
}
mochaIt(title, testFn)
}
before = function(f) {
var testFn = f.length < 2 ?
function() {
f.call(this,testData)
} :
function(done) {
f.call(this,testData,done)
}
mochaBefore(testFn)
}
fn()
} finally {
it = mochaIt
before = mochaBefore
}
})
}