Bug 1409195 - Improve Assert.throws documentation r?ato draft
authorPeter Major <majorpetya@gmail.com>
Wed, 18 Oct 2017 23:28:37 +0100
changeset 683140 f23c82338a28589a1f700e47c71849d73a401667
parent 683139 097044f71d4a4057dcc7bf76030f8b4cc379b56c
child 736536 270d084dd7db1990837f17069fd2d0e64c37fc07
push id85260
push userbmo:majorpetya@gmail.com
push dateThu, 19 Oct 2017 08:18:05 +0000
reviewersato
bugs1409195
milestone58.0a1
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
testing/modules/Assert.jsm
--- 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, "<=");
 };
-