@travetto/test
Advanced tools
Comparing version 0.0.38 to 0.0.39
@@ -31,3 +31,3 @@ { | ||
}, | ||
"version": "0.0.38" | ||
"version": "0.0.39" | ||
} |
@@ -10,3 +10,3 @@ import { Class } from '@travetto/registry/src/model/types'; | ||
methodName: string; | ||
shouldError?: string | RegExp | Function | boolean; | ||
shouldThrow?: string | RegExp | Function | boolean; | ||
skip: boolean; | ||
@@ -13,0 +13,0 @@ timeout?: number; |
@@ -114,33 +114,25 @@ import * as fs from 'fs'; | ||
static checkError(test: TestConfig, err: Error | string | undefined) { | ||
if (test.shouldError && test.shouldError) { | ||
if (typeof test.shouldError === 'boolean') { | ||
if (err && !test.shouldError) { | ||
throw new Error('Expected an error to not be thrown'); | ||
} else if (!err && test.shouldError) { | ||
throw new Error('Expected an error to be thrown'); | ||
} | ||
return; | ||
} else if (typeof test.shouldError === 'string') { | ||
if (err === undefined || !(err instanceof Error ? err.message : err).includes(test.shouldError)) { | ||
return new Error(`Expected error containing text ${test.shouldError}`); | ||
} else { | ||
return; | ||
} | ||
} else if (test.shouldError instanceof RegExp) { | ||
if (err !== undefined && test.shouldError.test(typeof err === 'string' ? err : err.message)) { | ||
return; | ||
} else { | ||
return new Error(`Expected error with message matching ${test.shouldError.source}`); | ||
} | ||
} else if (test.shouldError === Error || Object.getPrototypeOf(test.shouldError).constructor !== Function) { // if not simple function, treat as class | ||
if (!err || !(err instanceof test.shouldError)) { | ||
return new Error(`Expected to throw ${test.shouldError.name}`); | ||
} else { | ||
return; | ||
} | ||
} else if (test.shouldError(err)) { | ||
return; | ||
const st = test.shouldThrow!; | ||
if (typeof st === 'boolean') { | ||
if (err && !st) { | ||
throw new Error('Expected an error to not be thrown'); | ||
} else if (!err && st) { | ||
throw new Error('Expected an error to be thrown'); | ||
} | ||
} else if (typeof st === 'string') { | ||
if (!err || !(err instanceof Error ? err.message : err).includes(st)) { | ||
return new Error(`Expected error containing text ${st}`); | ||
} | ||
} else if (st instanceof RegExp) { | ||
if (!err || !st.test(typeof err === 'string' ? err : err.message)) { | ||
return new Error(`Expected error with message matching ${st.source}`); | ||
} | ||
} else if (st === Error || st === BaseError || Object.getPrototypeOf(st).constructor !== Function) { // if not simple function, treat as class | ||
if (!err || !(err instanceof st)) { | ||
return new Error(`Expected to throw ${st.name}`); | ||
} | ||
} else { | ||
return st(err); | ||
} | ||
return err; | ||
} | ||
@@ -183,3 +175,3 @@ | ||
err = new Error('Operation timed out'); | ||
} else { | ||
} else if (test.shouldThrow) { | ||
err = this.checkError(test, err); | ||
@@ -201,13 +193,12 @@ } | ||
const assrt = { | ||
AssertUtil.add({ | ||
className: test.className, | ||
error: err, | ||
methodName: test.methodName, | ||
file: test.file, | ||
line, | ||
operator: 'throws', | ||
error: err, | ||
message: err.message, | ||
file: test.file, | ||
text: '(uncaught)', | ||
line | ||
} | ||
AssertUtil.add(assrt); | ||
text: '(uncaught)' | ||
}); | ||
} | ||
@@ -214,0 +205,0 @@ } |
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
47610
1356