Skip to content

Commit

Permalink
Adds throws method to asserting
Browse files Browse the repository at this point in the history
  • Loading branch information
acadet committed Oct 16, 2014
1 parent 9061b86 commit cfaf581
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.tscache/
node_modules/
tscommand*.txt
.coverage_data/

# Exclude from repo
out/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oscar",
"version": "1.0.0",
"version": "1.0.1",
"devDependencies": {
"grunt": "~0.4.5",
"grunt-ts": "~1.12.1",
Expand Down
20 changes: 20 additions & 0 deletions src/Assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@ class Assert {
throw new Error('Unexpected ' + unexpected + ' instead of ' + value);
}
}

/**
* Asserts provided function to throw an error
* @param {() => void} func [description]
*/
static throws(func : () => void) : void {
var hasFailed : boolean;

hasFailed = false;

try {
func();
} catch (e) {
hasFailed = true;
} finally {
if (!hasFailed) {
throw new Error('Expected function to throw an error');
}
}
}

//endregion Public Methods

Expand Down

0 comments on commit cfaf581

Please sign in to comment.