async-test-util
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -48,3 +48,3 @@ import _regeneratorRuntime from 'babel-runtime/regenerator'; | ||
case 12: | ||
return _context.abrupt('return', 'util.assertThrowsAsync(): everything is fine'); | ||
return _context.abrupt('return', _context.t0); | ||
@@ -51,0 +51,0 @@ case 13: |
@@ -62,3 +62,3 @@ 'use strict'; | ||
case 12: | ||
return _context.abrupt('return', 'util.assertThrowsAsync(): everything is fine'); | ||
return _context.abrupt('return', _context.t0); | ||
@@ -65,0 +65,0 @@ case 13: |
{ | ||
"name": "async-test-util", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Util-functions that are be useful in async tests", | ||
@@ -31,3 +31,3 @@ "main": "./dist/lib/index.js", | ||
"babel-core": "6.26.0", | ||
"babel-eslint": "8.2.0", | ||
"babel-eslint": "8.2.1", | ||
"babel-loader": "7.1.2", | ||
@@ -34,0 +34,0 @@ "babel-plugin-transform-async-to-generator": "6.24.1", |
@@ -147,2 +147,17 @@ # async-test-util | ||
}); | ||
// assertThrows returns the error | ||
it('should have the custom error-property', async() => { | ||
const throwingFunction = async()=>{ | ||
const error = new Error('error message'); | ||
error.foo = 'bar'; | ||
throw error; | ||
} | ||
const thrown = await AsyncTestUtil.assertThrows( | ||
() => pingServer(), // function that throws (required) | ||
Error, // Error-type (optional) | ||
'message' // text-flag, throw if error-message does not include this (optional) | ||
); | ||
assert.equal(thrown.foo, 'bar'); | ||
}); | ||
``` | ||
@@ -152,4 +167,3 @@ | ||
Recieves an object with promises as values. Returns ans object with the resolved promises as values. | ||
Use this in test-setups to improve the test-speed by running everything in parallel. | ||
Recieves an object with promises as values. Returns ans object with the resolved promises as values. Use this in test-setups to improve the test-speed by running everything in parallel. | ||
@@ -173,6 +187,4 @@ ```javascript | ||
}); | ||
``` | ||
## randomString() | ||
@@ -197,3 +209,2 @@ | ||
## randomNumber() | ||
@@ -213,3 +224,2 @@ | ||
// > 1768 | ||
``` | ||
@@ -216,0 +226,0 @@ |
@@ -34,3 +34,3 @@ /** | ||
// all is ok | ||
return 'util.assertThrowsAsync(): everything is fine'; | ||
return e; | ||
} | ||
@@ -37,0 +37,0 @@ throw new Error( |
@@ -52,3 +52,3 @@ /** | ||
*/ | ||
export function assertThrows(fun: Function, error?: any, contains?: 'string'): Promise<void>; | ||
export function assertThrows(fun: Function, error?: any, contains?: 'string'): Promise<Error | TypeError>; | ||
@@ -55,0 +55,0 @@ /** |
@@ -5,3 +5,3 @@ const assert = require('assert'); | ||
describe('assert-throws.test.js', () => { | ||
it('valid if function throws', async() => { | ||
it('valid if function throws', async () => { | ||
const test = async function() { | ||
@@ -16,3 +16,3 @@ await AsyncTestUtil.wait(1); | ||
}); | ||
it('throw if function does not throw', async() => { | ||
it('throw if function does not throw', async () => { | ||
const test = async function() { | ||
@@ -33,3 +33,3 @@ await AsyncTestUtil.wait(1); | ||
}); | ||
it('throw if no TypeError', async() => { | ||
it('throw if no TypeError', async () => { | ||
const test = async function() { | ||
@@ -50,3 +50,3 @@ await AsyncTestUtil.wait(1); | ||
}); | ||
it('throw if no Error', async() => { | ||
it('throw if no Error', async () => { | ||
const test = async function() { | ||
@@ -67,3 +67,3 @@ await AsyncTestUtil.wait(1); | ||
}); | ||
it('throw if not contains', async() => { | ||
it('throw if not contains', async () => { | ||
const test = async function() { | ||
@@ -85,3 +85,3 @@ await AsyncTestUtil.wait(1); | ||
}); | ||
it('dont throw if contains', async() => { | ||
it('dont throw if contains', async () => { | ||
const test = async function() { | ||
@@ -97,3 +97,3 @@ await AsyncTestUtil.wait(1); | ||
}); | ||
it('compare to custom error', async() => { | ||
it('compare to custom error', async () => { | ||
class CustomError extends Error { | ||
@@ -124,2 +124,17 @@ constructor(message) { | ||
}); | ||
it('should return the error', async () => { | ||
const throwingFunction = async () => { | ||
await Promise.resolve(); | ||
const error = new Error('foobar'); | ||
error.foo = 'bar'; | ||
throw error; | ||
}; | ||
// via class | ||
const ret = await AsyncTestUtil.assertThrows( | ||
() => throwingFunction(), | ||
Error, | ||
'foobar' | ||
); | ||
assert.equal(ret.foo, 'bar'); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73323
1436
255