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
--- a/toolkit/components/promiseworker/tests/xpcshell/data/worker.js
+++ b/toolkit/components/promiseworker/tests/xpcshell/data/worker.js
@@ -21,10 +21,14 @@ worker.close = function() {
worker.log = function(...args) {
dump("Worker: " + args.join(" ") + "\n");
};
self.addEventListener("message", msg => worker.handleMessage(msg));
var Agent = {
bounce: function(...args) {
return args;
- }
+ },
+
+ throwError: function(msg, ...args) {
+ throw new Error(msg);
+ },
};
--- a/toolkit/components/promiseworker/tests/xpcshell/test_Promise.js
+++ b/toolkit/components/promiseworker/tests/xpcshell/test_Promise.js
@@ -101,8 +101,17 @@ add_task(function* test_transfer_with_me
Assert.equal(Object.prototype.toString.call(result), "[object Uint8Array]",
"The result appears to be a Typed Array");
Assert.equal(result.byteLength, 4, "The result has the right size");
for (let i = 0; i < 4; ++i) {
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");
+ }
+});