From 90f5226666dc52a0ec9ccfe8236534cfc4f6848a Mon Sep 17 00:00:00 2001 From: Gregory Szorc Date: Sat, 24 Sep 2016 19:31:48 -0700 Subject: [PATCH] Bug 1305444 - Add test for dispatched method throwing an error; r=Yoric We didn't have explicit test coverage of this before, surprisingly. MozReview-Commit-ID: 32ZnxZYLXDg --HG-- extra : rebase_source : 07110ed90b69c5b0fb73fda8264db2eb755ca6a4 --- .../promiseworker/tests/xpcshell/data/worker.js | 6 +++++- .../promiseworker/tests/xpcshell/test_Promise.js | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/toolkit/components/promiseworker/tests/xpcshell/data/worker.js b/toolkit/components/promiseworker/tests/xpcshell/data/worker.js index 3c612a528691..b4750788b5ce 100644 --- a/toolkit/components/promiseworker/tests/xpcshell/data/worker.js +++ b/toolkit/components/promiseworker/tests/xpcshell/data/worker.js @@ -26,5 +26,9 @@ self.addEventListener("message", msg => worker.handleMessage(msg)); var Agent = { bounce: function(...args) { return args; - } + }, + + throwError: function(msg, ...args) { + throw new Error(msg); + }, }; diff --git a/toolkit/components/promiseworker/tests/xpcshell/test_Promise.js b/toolkit/components/promiseworker/tests/xpcshell/test_Promise.js index a2df6fb4387b..70f49e92e0c5 100644 --- a/toolkit/components/promiseworker/tests/xpcshell/test_Promise.js +++ b/toolkit/components/promiseworker/tests/xpcshell/test_Promise.js @@ -106,3 +106,12 @@ add_task(function* test_transfer_with_meta() { Assert.equal(result[i], i); } }); + +add_task(function* test_throw_error() { + try { + yield worker.post("throwError", ["error message"]); + Assert.ok(false, "should have thrown"); + } catch (ex) { + Assert.equal(ex.message, "Error: error message"); + } +});