Skip to content

Commit cfaf581

Browse files
committed
Adds throws method to asserting
1 parent 9061b86 commit cfaf581

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
.tscache/
55
node_modules/
66
tscommand*.txt
7+
.coverage_data/
78

89
# Exclude from repo
910
out/

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "oscar",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"devDependencies": {
55
"grunt": "~0.4.5",
66
"grunt-ts": "~1.12.1",

src/Assert.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,26 @@ class Assert {
7878
throw new Error('Unexpected ' + unexpected + ' instead of ' + value);
7979
}
8080
}
81+
82+
/**
83+
* Asserts provided function to throw an error
84+
* @param {() => void} func [description]
85+
*/
86+
static throws(func : () => void) : void {
87+
var hasFailed : boolean;
88+
89+
hasFailed = false;
90+
91+
try {
92+
func();
93+
} catch (e) {
94+
hasFailed = true;
95+
} finally {
96+
if (!hasFailed) {
97+
throw new Error('Expected function to throw an error');
98+
}
99+
}
100+
}
81101

82102
//endregion Public Methods
83103

0 commit comments

Comments
 (0)