Bug 1371733 - Propagate error message of assert.object; r?whimboo draft
authorAndreas Tolfsen <ato@sny.no>
Mon, 12 Jun 2017 18:02:39 +0100
changeset 599055 7c4028e64201e5c84c73d30ed5724a1be9ac088d
parent 599054 de52d399dcf8570c4e0b4a081e58291582a7f82b
child 599056 7b47a42c07e8010e7950de9efc7309b4dbd09841
push id65413
push userbmo:ato@sny.no
push dateThu, 22 Jun 2017 16:50:45 +0000
reviewerswhimboo
bugs1371733
milestone56.0a1
Bug 1371733 - Propagate error message of assert.object; r?whimboo The err argument to assert.object is currently being dropped, which means we loose the specialised and the custom error message. This patch propagates the error message like we do for all other assertions in this module. MozReview-Commit-ID: GwuBSbqKfk1
testing/marionette/assert.js
testing/marionette/test_assert.js
--- a/testing/marionette/assert.js
+++ b/testing/marionette/assert.js
@@ -298,17 +298,17 @@ assert.string = function (obj, msg = "")
  */
 assert.object = function (obj, msg = "") {
   msg = msg || error.pprint`Expected ${obj} to be an object`;
   return assert.that(o => {
     // unable to use instanceof because LHS and RHS may come from
     // different globals
     let s = Object.prototype.toString.call(o);
     return s == "[object Object]" || s == "[object nsJSIID]";
-  })(obj);
+  }, msg)(obj);
 };
 
 /**
  * Asserts that |prop| is in |obj|.
  *
  * @param {?} prop
  *     Own property to test if is in |obj|.
  * @param {?} obj
--- a/testing/marionette/test_assert.js
+++ b/testing/marionette/test_assert.js
@@ -131,16 +131,18 @@ add_test(function test_contentBrowser() 
 
 add_test(function test_object() {
   assert.object({});
   assert.object(new Object());
   for (let typ of [42, "foo", true, null, undefined]) {
     Assert.throws(() => assert.object(typ), InvalidArgumentError);
   }
 
+  Assert.throws(() => assert.object(null, "custom"), /custom/);
+
   run_next_test();
 });
 
 add_test(function test_in() {
   assert.in("foo", {foo: 42});
   for (let typ of [{}, 42, true, null, undefined]) {
     Assert.throws(() => assert.in("foo", typ), InvalidArgumentError);
   }