Bug 1470455 - Add the 'expected' arguments to throws/rejects for devtools. r?jdescottes draft
authorMark Banner <standard8@mozilla.com>
Thu, 21 Jun 2018 16:56:08 +0100
changeset 812465 4f91b877499cb62eb6cc6b958e2d5439b3adc30e
parent 812437 bf149090f6b5db3fe86618b5f1047b70b1bff8b5
child 812466 60431b09f03e48171ea7eb160a657acf34c8a8fa
push id114559
push userbmo:standard8@mozilla.com
push dateFri, 29 Jun 2018 13:19:23 +0000
reviewersjdescottes
bugs1470455
milestone63.0a1
Bug 1470455 - Add the 'expected' arguments to throws/rejects for devtools. r?jdescottes MozReview-Commit-ID: 3HmVFhiA2FZ
devtools/client/shared/test/unit/test_suggestion-picker.js
devtools/shared/heapsnapshot/tests/unit/test_SaveHeapSnapshot.js
--- a/devtools/client/shared/test/unit/test_suggestion-picker.js
+++ b/devtools/client/shared/test/unit/test_suggestion-picker.js
@@ -133,17 +133,17 @@ function ensureMostRelevantIndexProvided
     const mostRelevantIndex = findMostRelevantCssPropertyIndex(items);
     strictEqual(mostRelevantIndex, expectedIndex);
   }
 }
 
 function ensureErrorThrownWithInvalidArguments() {
   info("Running ensureErrorThrownWithInvalidTypeArgument()");
 
-  const expectedError = "Please provide valid items and sortedItems arrays.";
+  const expectedError = /Please provide valid items and sortedItems arrays\./;
   // No arguments passed.
-  throws(() => findMostRelevantIndex(), expectedError);
+  Assert.throws(() => findMostRelevantIndex(), expectedError);
   // Invalid arguments passed.
-  throws(() => findMostRelevantIndex([]), expectedError);
-  throws(() => findMostRelevantIndex(null, []), expectedError);
-  throws(() => findMostRelevantIndex([], "string"), expectedError);
-  throws(() => findMostRelevantIndex("string", []), expectedError);
+  Assert.throws(() => findMostRelevantIndex([]), expectedError);
+  Assert.throws(() => findMostRelevantIndex(null, []), expectedError);
+  Assert.throws(() => findMostRelevantIndex([], "string"), expectedError);
+  Assert.throws(() => findMostRelevantIndex("string", []), expectedError);
 }
--- a/devtools/shared/heapsnapshot/tests/unit/test_SaveHeapSnapshot.js
+++ b/devtools/shared/heapsnapshot/tests/unit/test_SaveHeapSnapshot.js
@@ -13,50 +13,62 @@ function run_test() {
 
   testBadParameters();
   testGoodParameters();
 
   do_test_finished();
 }
 
 function testBadParameters() {
-  throws(() => ChromeUtils.saveHeapSnapshot(),
-         "Should throw if arguments aren't passed in.");
+  Assert.throws(() => ChromeUtils.saveHeapSnapshot(),
+                /NS_ERROR_ILLEGAL_VALUE/,
+                "Should throw if arguments aren't passed in.");
 
-  throws(() => ChromeUtils.saveHeapSnapshot(null),
-         "Should throw if boundaries isn't an object.");
+  Assert.throws(() => ChromeUtils.saveHeapSnapshot(null),
+                /NS_ERROR_ILLEGAL_VALUE/,
+                "Should throw if boundaries isn't an object.");
 
-  throws(() => ChromeUtils.saveHeapSnapshot({}),
-         "Should throw if the boundaries object doesn't have any properties.");
+  Assert.throws(() => ChromeUtils.saveHeapSnapshot({}),
+                /NS_ERROR_ILLEGAL_VALUE/,
+                "Should throw if the boundaries object doesn't have any properties.");
 
-  throws(() => ChromeUtils.saveHeapSnapshot({ runtime: true,
-                                              globals: [this] }),
-         "Should throw if the boundaries object has more than one property.");
+  Assert.throws(() => ChromeUtils.saveHeapSnapshot({ runtime: true,
+                                                     globals: [this] }),
+                /NS_ERROR_ILLEGAL_VALUE/,
+                "Should throw if the boundaries object has more than one property.");
 
-  throws(() => ChromeUtils.saveHeapSnapshot({ debugger: {} }),
-         "Should throw if the debuggees object is not a Debugger object");
+  Assert.throws(() => ChromeUtils.saveHeapSnapshot({ debugger: {} }),
+                /NS_ERROR_ILLEGAL_VALUE/,
+                "Should throw if the debuggees object is not a Debugger object");
 
-  throws(() => ChromeUtils.saveHeapSnapshot({ globals: [{}] }),
-         "Should throw if the globals array contains non-global objects.");
+  Assert.throws(() => ChromeUtils.saveHeapSnapshot({ globals: [{}] }),
+                /NS_ERROR_ILLEGAL_VALUE/,
+                "Should throw if the globals array contains non-global objects.");
 
-  throws(() => ChromeUtils.saveHeapSnapshot({ runtime: false }),
-         "Should throw if runtime is supplied and is not true.");
+  Assert.throws(() => ChromeUtils.saveHeapSnapshot({ runtime: false }),
+                /NS_ERROR_ILLEGAL_VALUE/,
+                "Should throw if runtime is supplied and is not true.");
 
-  throws(() => ChromeUtils.saveHeapSnapshot({ globals: null }),
-         "Should throw if globals is not an object.");
+  Assert.throws(() => ChromeUtils.saveHeapSnapshot({ globals: null }),
+                /TypeError:.*can't be converted to a sequence/,
+                "Should throw if globals is not an object.");
 
-  throws(() => ChromeUtils.saveHeapSnapshot({ globals: {} }),
-         "Should throw if globals is not an array.");
+  Assert.throws(() => ChromeUtils.saveHeapSnapshot({ globals: {} }),
+                /TypeError:.*can't be converted to a sequence/,
+                "Should throw if globals is not an array.");
 
-  throws(() => ChromeUtils.saveHeapSnapshot({ debugger: Debugger.prototype }),
-         "Should throw if debugger is the Debugger.prototype object.");
+  Assert.throws(() => ChromeUtils.saveHeapSnapshot({ debugger: Debugger.prototype }),
+                /NS_ERROR_ILLEGAL_VALUE/,
+                "Should throw if debugger is the Debugger.prototype object.");
 
-  throws(() => ChromeUtils.saveHeapSnapshot({ get globals() {
+  Assert.throws(() => ChromeUtils.saveHeapSnapshot({ get globals() {
     return [this];
-  } }), "Should throw if boundaries property is a getter.");
+  } }),
+                /NS_ERROR_ILLEGAL_VALUE/,
+                "Should throw if boundaries property is a getter.");
 }
 
 const makeNewSandbox = () =>
   Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")());
 
 function testGoodParameters() {
   const sandbox = makeNewSandbox();
   let dbg = new Debugger(sandbox);