thunk-test
Advanced tools
Comparing version 0.2.7 to 0.3.0
{ | ||
"name": "thunk-test", | ||
"version": "0.2.7", | ||
"version": "0.3.0", | ||
"description": "Modular testing for JavaScript", | ||
@@ -5,0 +5,0 @@ "author": "Richard Tong", |
@@ -5,12 +5,35 @@ # ThunkTest | ||
```javascript | ||
const add = (a, b) => a + b | ||
ThunkTest('adds two values', add) | ||
.case(5, 5, 10) | ||
.case('abcde', 'fg', result => { | ||
assert.strictEqual(result, 'abcdefg') | ||
ThunkTest( | ||
'pipe: awesome username generator', | ||
pipe([ | ||
string => string.toUpperCase(), | ||
string => `x${string}x`, | ||
string => `X${string}X`, | ||
string => `x${string}x`, | ||
string => `_${string}_`, | ||
])) | ||
.case('deimos', '_xXxDEIMOSxXx_') // objects deep equal, otherwise strict equal | ||
.case('|', result => assert.equal(result, '_xXx|xXx_')) // can supply a callback | ||
.case('?', async result => assert.equal(result, '_xXx?xXx_')) // async ok | ||
.throws(1, new TypeError('string.toUpperCase is not a function')) | ||
.throws(null, (err, arg0) => { | ||
assert.strictEqual(arg0, null) | ||
assert.strictEqual(err.name, 'TypeError') | ||
assert.strictEqual(err.message, 'Cannot read property \'toUpperCase\' of null') | ||
})() | ||
// adds two values | ||
// ✓ (5, 5) -> 10 | ||
// ✓ ('abcde', 'fg') -> callback(...) | ||
// pipe: awesome username generator | ||
// ✓ pipeline('deimos') -> '_xXxDEIMOSxXx_' | ||
// ✓ pipeline('|') -> result => assert.equal(result, '_xXx|xXx_') | ||
// ✓ pipeline(1) throws TypeError: string.toUpperCase is not a function | ||
// ✓ pipeline(null) throws; (err, arg0) => { | ||
// assert.strictEqual(arg0, null) | ||
// assert.strictEqual(err.name, 'TypeError') | ||
// assert.strictEqual(err.message, 'Cannot read property \'toUpperCase\' of null') | ||
// } | ||
// ✓ pipeline('?') -> async result => assert.equal(result, '_xXx?xXx_') | ||
// ✓ pipeline(NaN) throws; async (err, arg0) => { | ||
// assert.strictEqual(arg0, NaN) | ||
// assert.strictEqual(err.name, 'TypeError') | ||
// assert.strictEqual(err.message, 'string.toUpperCase is not a function') | ||
// } | ||
``` | ||
@@ -17,0 +40,0 @@ |
@@ -19,3 +19,2 @@ const ThunkTest = require('./thunk-test') | ||
pipe([ | ||
(arg0, arg1) => arg1 == null ? arg0 : arg0 + arg1, | ||
string => string.toUpperCase(), | ||
@@ -25,7 +24,7 @@ string => `x${string}x`, | ||
string => `x${string}x`, | ||
string => `_${string}_`, | ||
])) | ||
.case('deimos', 'xXxDEIMOSxXx') // result default deepEqual; last argument is expected result | ||
.case('aa', 'bb', 'xXxAABBxXx') // multiple arguments | ||
.case('|', result => assert.equal(result, 'xXx|xXx')) // can supply a callback | ||
.case('?', async result => assert.equal(result, 'xXx?xXx')) // async ok | ||
.case('deimos', '_xXxDEIMOSxXx_') // objects deep equal, otherwise strict equal | ||
.case('|', result => assert.equal(result, '_xXx|xXx_')) // can supply a callback | ||
.case('?', async result => assert.equal(result, '_xXx?xXx_')) // async ok | ||
.throws(1, new TypeError('string.toUpperCase is not a function')) | ||
@@ -32,0 +31,0 @@ .throws(null, (err, arg0) => { |
@@ -403,6 +403,6 @@ const noop = function () {} | ||
return execution.then(funcConcat( | ||
tapSync(thunkify1(log, ` ✓ ${argsInspect(args)} throws ...`)), | ||
tapSync(thunkify1(log, ` ✓ ${funcSignature(func, args)} throws ${funcInspect(callback)}`)), | ||
noop)) | ||
} | ||
log(` ✓ ${argsInspect(args)} throws ...`) | ||
log(` ✓ ${funcSignature(func, args)} throws ${funcInspect(callback)}`) | ||
return undefined | ||
@@ -492,3 +492,3 @@ } | ||
thunkify2(assertThrows, thunkifyArgs(func, args), expected), | ||
tapSync(thunkify1(log, ` ✓ ${argsInspect(args)} throws ${expected}`)), | ||
tapSync(thunkify1(log, ` ✓ ${funcSignature(func, args)} throws ${expected}`)), | ||
)) | ||
@@ -495,0 +495,0 @@ } |
16863
55
511