Skip to content

Commit

Permalink
Toward #3: First crack at throws
Browse files Browse the repository at this point in the history
  • Loading branch information
jmakeig committed Aug 31, 2016
1 parent 43ed723 commit d2ef70c
Showing 1 changed file with 44 additions and 6 deletions.
50 changes: 44 additions & 6 deletions test.js
Expand Up @@ -81,9 +81,17 @@ Test.prototype = {
this.complete();
return this.report();
},
/////////////////////////////////////////////////////////////////////
pass(message) {
this.outcomes.push({type: 'pass', message: message});
report() {
return this.outcomes;
},
/**
*
*
* @param {string} message
* @param {string} operator
*/
pass(message, operator) {
this.outcomes.push({type: 'pass', operator: operator, message: message});
},
/**
*
Expand Down Expand Up @@ -150,6 +158,7 @@ Test.prototype = {
);
}
},
//////////// Assertions ////////////
true(actual, message) {
// TODO: Check this.isEnded
message = message || `false`;
Expand All @@ -164,15 +173,44 @@ Test.prototype = {
);
}
},
false(actual, message) {
return this.true(
!actual,
message
);
},
equal(actual, expected, message) {
return this.true(
expected === actual,
message
);
},
report() {
return this.outcomes;
}

/**
* Assert that the function call fn() throws an exception. expected, if present,
* must be a RegExp or Function. The RegExp matches the string representation of
* the exception, as generated by err.toString(). The Function is the exception
* thrown (e.g. Error). msg is an optional description of the assertion.
*
* @param {function} fn
* @param {Error} expected
* @param {string} message
* @returns void
*/
throws(fn, expected, message) {
let actual;
try {
fn();
} catch (error) {
if(error instanceof expected) {
this.pass(message, 'throws');
return;
} else {
actual = error;
}
}
this.fail(message, expected, actual, StackTrace.parse(actual));
},
}

function test(name, impl) {
Expand Down

0 comments on commit d2ef70c

Please sign in to comment.