From 7d70bcd8419e7ef7d75f24721e2fca442ea03812 Mon Sep 17 00:00:00 2001 From: Joel Chen Date: Thu, 9 Apr 2020 17:45:04 -0700 Subject: [PATCH] fix: add tests --- .../electrode-react-webapp/lib/render-output.js | 2 +- .../test/spec/render-output.spec.js | 14 ++++++++++++++ packages/subapp-web/lib/util.js | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/electrode-react-webapp/lib/render-output.js b/packages/electrode-react-webapp/lib/render-output.js index 63fa83834..901039f6e 100644 --- a/packages/electrode-react-webapp/lib/render-output.js +++ b/packages/electrode-react-webapp/lib/render-output.js @@ -27,7 +27,7 @@ class Output { out += x.stringify(); } else { const typeName = (x && x.constructor && x.constructor.name) || typeof x; - const msg = `SpotOutput unable to stringify item of type ${typeName}`; + const msg = `RenderOutput unable to stringify item of type ${typeName}`; console.error("FATAL Error:", msg + "\n"); // eslint-disable-line throw new Error(msg); } diff --git a/packages/electrode-react-webapp/test/spec/render-output.spec.js b/packages/electrode-react-webapp/test/spec/render-output.spec.js index f2cdfb1a5..2fbd0a247 100644 --- a/packages/electrode-react-webapp/test/spec/render-output.spec.js +++ b/packages/electrode-react-webapp/test/spec/render-output.spec.js @@ -185,4 +185,18 @@ describe("render-output", function() { }; expect(() => ro._finish()).to.throw("test error"); }); + + it("should throw if can't stringify an item", () => { + const ro = new RenderOutput(); + ro.add({}); + expect(() => ro.flush()).to.throw("unable to stringify item of type Object"); + }); + + it("should throw if can't stringify an item without constructor", () => { + const ro = new RenderOutput(); + const item = {}; + item.constructor = false; + ro.add(item); + expect(() => ro.flush()).to.throw("unable to stringify item of type object"); + }); }); diff --git a/packages/subapp-web/lib/util.js b/packages/subapp-web/lib/util.js index c8c646de9..90b0ef55e 100644 --- a/packages/subapp-web/lib/util.js +++ b/packages/subapp-web/lib/util.js @@ -1,6 +1,6 @@ "use strict"; -/* eslint-disable global-require, max-statements, no-loop-func */ +/* eslint-disable global-require, max-statements, no-loop-func, max-len */ const Fs = require("fs"); const assert = require("assert");