Bug 1371733 - Add tests for custom assertion errors; r?whimboo draft
authorAndreas Tolfsen <ato@sny.no>
Mon, 12 Jun 2017 18:18:48 +0100
changeset 599056 7b47a42c07e8010e7950de9efc7309b4dbd09841
parent 599055 7c4028e64201e5c84c73d30ed5724a1be9ac088d
child 599057 935c439bf64bbc8957daa22b91c3850a5be8ff99
push id65413
push userbmo:ato@sny.no
push dateThu, 22 Jun 2017 16:50:45 +0000
reviewerswhimboo
bugs1371733
milestone56.0a1
Bug 1371733 - Add tests for custom assertion errors; r?whimboo The last commit discovered a bug that one assertion's error message was not being propagated. This adds extensive tests for this, for all the remaining assertions to ensure this does not regress in the future. MozReview-Commit-ID: EK91mUPeweG
testing/marionette/test_assert.js
--- a/testing/marionette/test_assert.js
+++ b/testing/marionette/test_assert.js
@@ -10,16 +10,18 @@ Cu.import("chrome://marionette/content/a
 Cu.import("chrome://marionette/content/error.js");
 
 add_test(function test_session() {
   assert.session({sessionId: "foo"});
   for (let typ of [null, undefined, ""]) {
     Assert.throws(() => assert.session({sessionId: typ}), InvalidSessionIDError);
   }
 
+  Assert.throws(() => assert.session({sessionId: null}, "custom"), /custom/);
+
   run_next_test();
 });
 
 add_test(function test_platforms() {
   // at least one will fail
   let raised;
   for (let fn of [assert.firefox, assert.fennec]) {
     try {
@@ -33,91 +35,110 @@ add_test(function test_platforms() {
   run_next_test();
 });
 
 add_test(function test_noUserPrompt() {
   assert.noUserPrompt(null);
   assert.noUserPrompt(undefined);
   Assert.throws(() => assert.noUserPrompt({}), UnexpectedAlertOpenError);
 
+  Assert.throws(() => assert.noUserPrompt({}, "custom"), /custom/);
+
   run_next_test();
 });
 
 add_test(function test_defined() {
   assert.defined({});
   Assert.throws(() => assert.defined(undefined), InvalidArgumentError);
 
+  Assert.throws(() => assert.noUserPrompt({}, "custom"), /custom/);
+
   run_next_test();
 });
 
 add_test(function test_number() {
   assert.number(1);
   assert.number(0);
   assert.number(-1);
   assert.number(1.2);
   for (let i of ["foo", "1", {}, [], NaN, Infinity, undefined]) {
     Assert.throws(() => assert.number(i), InvalidArgumentError);
   }
+
+  Assert.throws(() => assert.number("foo", "custom"), /custom/);
+
   run_next_test();
 });
 
 add_test(function test_callable() {
   assert.callable(function () {});
   assert.callable(() => {});
 
   for (let typ of [undefined, "", true, {}, []]) {
     Assert.throws(() => assert.callable(typ), InvalidArgumentError);
   }
 
+  Assert.throws(() => assert.callable("foo", "custom"), /custom/);
+
   run_next_test();
 });
 
 add_test(function test_integer() {
   assert.integer(1);
   assert.integer(0);
   assert.integer(-1);
   Assert.throws(() => assert.integer("foo"), InvalidArgumentError);
   Assert.throws(() => assert.integer(1.2), InvalidArgumentError);
 
+  Assert.throws(() => assert.integer("foo", "custom"), /custom/);
+
   run_next_test();
 });
 
 add_test(function test_positiveInteger() {
   assert.positiveInteger(1);
   assert.positiveInteger(0);
   Assert.throws(() => assert.positiveInteger(-1), InvalidArgumentError);
   Assert.throws(() => assert.positiveInteger("foo"), InvalidArgumentError);
 
+  Assert.throws(() => assert.positiveInteger("foo", "custom"), /custom/);
+
   run_next_test();
 });
 
 add_test(function test_boolean() {
   assert.boolean(true);
   assert.boolean(false);
   Assert.throws(() => assert.boolean("false"), InvalidArgumentError);
   Assert.throws(() => assert.boolean(undefined), InvalidArgumentError);
 
+  Assert.throws(() => assert.boolean(undefined, "custom"), /custom/);
+
   run_next_test();
 });
 
 add_test(function test_string() {
   assert.string("foo");
   assert.string(`bar`);
   Assert.throws(() => assert.string(42), InvalidArgumentError);
 
+  Assert.throws(() => assert.string(42, "custom"), /custom/);
+
   run_next_test();
 });
 
 add_test(function test_window() {
   assert.window({closed: false});
 
   for (let typ of [null, undefined, {closed: true}]) {
     Assert.throws(() => assert.window(typ), NoSuchWindowError);
   }
 
+  Assert.throws(() => assert.window(null, "custom"), /custom/);
+
   run_next_test();
 });
 
 add_test(function test_contentBrowser() {
   assert.contentBrowser({contentBrowser: 42, window: {closed: false}});
 
   let closedWindow = {contentBrowser: 42, window: {closed: true}};
   let noContentBrowser = {contentBrowser: null, window: {closed: false}};
@@ -142,29 +163,35 @@ add_test(function test_object() {
 });
 
 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);
   }
 
+  Assert.throws(() => assert.in("foo", {bar: 42}, "custom"), /custom/);
+
   run_next_test();
 });
 
 add_test(function test_array() {
   assert.array([]);
   assert.array(new Array());
   Assert.throws(() => assert.array(42), InvalidArgumentError);
   Assert.throws(() => assert.array({}), InvalidArgumentError);
 
+  Assert.throws(() => assert.array(42, "custom"), /custom/);
+
   run_next_test();
 });
 
 add_test(function test_that() {
   equal(1, assert.that(n => n + 1)(1));
   Assert.throws(() => assert.that(() => false)());
   Assert.throws(() => assert.that(val => val)(false));
   Assert.throws(() => assert.that(val => val, "foo", SessionNotCreatedError)(false),
       SessionNotCreatedError);
 
+  Assert.throws(() => assert.that(() => false, "custom")(), /custom/);
+
   run_next_test();
 });