Bug 1409195 - Improve Assert.throws documentation r?ato
Added a new segment that should make it clearer that if the second
parameter of the throws method is of string type, the parameter
won't be used to verify the exception message.
MozReview-Commit-ID: 6pYRfQwNYPi
--- a/testing/modules/Assert.jsm
+++ b/testing/modules/Assert.jsm
@@ -325,20 +325,33 @@ function expectedException(actual, expec
return false;
}
/**
* 11. Expected to throw an error:
* assert.throws(block, Error_opt, message_opt);
*
+ * Example:
+ * ```js
+ * // The following will verify that an error of type TypeError was thrown:
+ * Assert.throws(() => testBody(), TypeError);
+ * // The following will verify that an error was thrown with an error message matching "hello":
+ * Assert.throws(() => testBody(), /hello/);
+ * // The following will verify that any error was thrown and will use "hello" in the test report:
+ * Assert.throws(() => testBody(), "hello");
+ * ```
+ *
* @param block
* (function) Function block to evaluate and catch eventual thrown errors
* @param expected (optional)
- * (mixed) Test reference to evaluate against the thrown result from `block`
+ * (mixed) This parameter can be either a RegExp, a function, or a string. The
+ * function is either the error type's constructor, or it's a method that returns a boolean
+ * that describes the test outcome. When string value is provided, it will be used as if it
+ * was provided as the message parameter.
* @param message (optional)
* (string) Short explanation of the expected result
*/
proto.throws = function(block, expected, message) {
let actual;
if (typeof expected === "string") {
message = expected;
@@ -468,9 +481,8 @@ proto.less = function less(lhs, rhs, mes
* @param rhs
* (number) The right-hand side value
* @param message (optional)
* (string) Short explanation of the comparison result
*/
proto.lessOrEqual = function lessOrEqual(lhs, rhs, message) {
compareNumbers.call(this, lhs > rhs, lhs, rhs, message, "<=");
};
-