tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_assert.js (1026B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test DevToolsUtils.assert
      7 
      8 ALLOW_CONSOLE_ERRORS = true;
      9 
     10 function run_test() {
     11  const { assert } = DevToolsUtils;
     12  equal(typeof assert, "function");
     13 
     14  try {
     15    assert(true, "this assertion should not fail");
     16  } catch (e) {
     17    // If you catch assertion failures in practice, I will hunt you down. I get
     18    // email notifications every time it happens.
     19    ok(
     20      false,
     21      "Should not get an error for an assertion that should not fail. Got " +
     22        DevToolsUtils.safeErrorString(e)
     23    );
     24  }
     25 
     26  let assertionFailed = false;
     27  try {
     28    assert(false, "this assertion should fail");
     29  } catch (e) {
     30    ok(
     31      e.message.startsWith("Assertion failure:"),
     32      "Should be an assertion failure error"
     33    );
     34    assertionFailed = true;
     35  }
     36 
     37  ok(
     38    assertionFailed,
     39    "The assertion should have failed, which should throw an error when assertions " +
     40      "are enabled."
     41  );
     42 }