thunk-test
Advanced tools
Comparing version 0.7.2 to 0.8.0
{ | ||
"name": "thunk-test", | ||
"version": "0.7.2", | ||
"version": "0.8.0", | ||
"description": "Modular testing for JavaScript", | ||
@@ -5,0 +5,0 @@ "author": "Richard Tong", |
@@ -86,4 +86,4 @@ # ThunkTest | ||
afterEach: function=>this, | ||
case: (...args, expectedResult|function=>())=>this, | ||
throws: (...args, expectedError)=>this, | ||
case: (...args, expectedResult|function=>(disposer ()=>Promise<>|())|())=>this, | ||
throws: (...args, expectedError|function=>(disposer ()=>Promise<>|())|())=>this, | ||
} | ||
@@ -90,0 +90,0 @@ |
25
test.js
@@ -87,2 +87,27 @@ const Test = require('./thunk-test') | ||
}), | ||
Test('disposer test', function range(from, to) { | ||
const result = [] | ||
for (let i = from; i < to; i++) { | ||
result.push(i) | ||
} | ||
return result | ||
}) | ||
.case(1, 6, function (numbers) { | ||
assert.deepEqual(numbers, [1, 2, 3, 4, 5]) | ||
return () => { | ||
this.hey = 'ho' | ||
} | ||
}) | ||
.case(0, 0, function (empty) { | ||
assert(Array.isArray(empty)) | ||
assert(empty.length == 0) | ||
return async () => { | ||
this.heyy = 'hoo' | ||
} | ||
}) | ||
.after(function () { | ||
assert.strictEqual(this.hey, 'ho') | ||
assert.strictEqual(this.heyy, 'hoo') | ||
}) | ||
] | ||
@@ -89,0 +114,0 @@ |
@@ -494,6 +494,12 @@ const noop = function () {} | ||
while (++operationsIndex < operationsLength) { | ||
const execution = operations[operationsIndex]() | ||
if (isPromise(execution)) { | ||
await execution | ||
let execution = operations[operationsIndex]() | ||
if (isPromise(execution)) { | ||
execution = await execution | ||
} | ||
if (typeof execution == 'function') { | ||
let cleanup = execution() | ||
if (isPromise(cleanup)) { | ||
await cleanup | ||
} | ||
} | ||
} | ||
@@ -518,4 +524,13 @@ } | ||
if (isPromise(execution)) { | ||
return execution.then(thunkify2( | ||
thunkTestExecAsync, operations, operationsIndex)) | ||
return execution.then(funcConcat( | ||
tapSync(res => typeof res == 'function' && res()), | ||
thunkify2(thunkTestExecAsync, operations, operationsIndex), | ||
)) | ||
} else if (typeof execution == 'function') { | ||
const cleanup = execution() | ||
if (isPromise(cleanup)) { | ||
return cleanup.then( | ||
thunkify2(thunkTestExecAsync, operations, operationsIndex), | ||
) | ||
} | ||
} | ||
@@ -530,12 +545,14 @@ } | ||
* ```coffeescript [specscript] | ||
* var story string, | ||
* func function, | ||
* args ...any, | ||
* expectedResult any, | ||
* expectedError Error|any | ||
* ThunkTest = ()=>() { | ||
* before: function=>this, | ||
* after: function=>this, | ||
* beforeEach: function=>this, | ||
* afterEach: function=>this, | ||
* case: (...args, expectedResult|function=>(disposer ()=>())|())=>this, | ||
* throws: (...args, expectedError|function=>(disposer ()=>())|())=>this, | ||
* } | ||
* | ||
* Test(story, func) -> thunkTest ()=>() { | ||
* case: (...args, expectedResult)=>this, | ||
* throws: (...args, expectedError)=>this, | ||
* } | ||
* Test(story string, func function) -> ThunkTest | ||
* | ||
* Test(func function) -> ThunkTest | ||
* ``` | ||
@@ -542,0 +559,0 @@ * |
25288
745