diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /devtools/shared/tests/unit/test_safeErrorString.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/shared/tests/unit/test_safeErrorString.js')
-rw-r--r-- | devtools/shared/tests/unit/test_safeErrorString.js | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/devtools/shared/tests/unit/test_safeErrorString.js b/devtools/shared/tests/unit/test_safeErrorString.js new file mode 100644 index 000000000..9892f34d1 --- /dev/null +++ b/devtools/shared/tests/unit/test_safeErrorString.js @@ -0,0 +1,58 @@ +/* -*- js-indent-level: 2; indent-tabs-mode: nil -*- */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test DevToolsUtils.safeErrorString + +function run_test() { + test_with_error(); + test_with_tricky_error(); + test_with_string(); + test_with_thrower(); + test_with_psychotic(); +} + +function test_with_error() { + let s = DevToolsUtils.safeErrorString(new Error("foo bar")); + // Got the message. + do_check_true(s.includes("foo bar")); + // Got the stack. + do_check_true(s.includes("test_with_error")); + do_check_true(s.includes("test_safeErrorString.js")); + // Got the lineNumber and columnNumber. + do_check_true(s.includes("Line")); + do_check_true(s.includes("column")); +} + +function test_with_tricky_error() { + let e = new Error("batman"); + e.stack = { toString: Object.create(null) }; + let s = DevToolsUtils.safeErrorString(e); + // Still got the message, despite a bad stack property. + do_check_true(s.includes("batman")); +} + +function test_with_string() { + let s = DevToolsUtils.safeErrorString("not really an error"); + // Still get the message. + do_check_true(s.includes("not really an error")); +} + +function test_with_thrower() { + let s = DevToolsUtils.safeErrorString({ + toString: () => { + throw new Error("Muahahaha"); + } + }); + // Still don't fail, get string back. + do_check_eq(typeof s, "string"); +} + +function test_with_psychotic() { + let s = DevToolsUtils.safeErrorString({ + toString: () => Object.create(null) + }); + // Still get a string out, and no exceptions thrown + do_check_eq(typeof s, "string"); + do_check_eq(s, "[object Object]"); +} |