From 8d14e811f9530bebf84660921dbbfcea78354ae9 Mon Sep 17 00:00:00 2001 From: ludbek Date: Mon, 11 Jul 2016 10:55:30 +0545 Subject: [PATCH 1/3] proper component check at m() --- mithril.js | 2 +- test/mithril.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/mithril.js b/mithril.js index 7ec24ab1..7ab4dcd3 100644 --- a/mithril.js +++ b/mithril.js @@ -152,7 +152,7 @@ args[i - 1] = arguments[i] } - if (isObject(tag)) return parameterize(tag, args) + if (tag && isFunction(tag.view)) return parameterize(tag, args) if (!isString(tag)) { throw new Error("selector in m(selector, attrs, children) should " + diff --git a/test/mithril.js b/test/mithril.js index 88111f51..5bffbb01 100644 --- a/test/mithril.js +++ b/test/mithril.js @@ -217,4 +217,32 @@ describe("m()", function () { m.component(component, args).controller() expect(spy.secondCall).to.have.been.calledWith(args) }) + + it("does not proxy to m.component() if the object does not have .view() method", function () { + var component = {} + + var args = {age: 12} + + expect(m.bind(m, component, args).to.throw(); + }) + + it("even proxies a function to m.component if it has .view() method", function () { + var spy = sinon.spy() + + var component = function () {}; + + var component.controller = spy; + var component.view = function () { + return m("div", "testing") + } + + var args = {age: 12} + + m(component, args).controller() + expect(spy.firstCall).to.have.been.calledWith(args) + + m.component(component, args).controller() + expect(spy.secondCall).to.have.been.calledWith(args) + }); + }) From cb64be965b63881d6bd22a03634471a4d0f327b8 Mon Sep 17 00:00:00 2001 From: ludbek Date: Mon, 11 Jul 2016 20:34:03 +0545 Subject: [PATCH 2/3] removed stupid test --- test/mithril.js | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/test/mithril.js b/test/mithril.js index 5bffbb01..c87bc142 100644 --- a/test/mithril.js +++ b/test/mithril.js @@ -225,24 +225,4 @@ describe("m()", function () { expect(m.bind(m, component, args).to.throw(); }) - - it("even proxies a function to m.component if it has .view() method", function () { - var spy = sinon.spy() - - var component = function () {}; - - var component.controller = spy; - var component.view = function () { - return m("div", "testing") - } - - var args = {age: 12} - - m(component, args).controller() - expect(spy.firstCall).to.have.been.calledWith(args) - - m.component(component, args).controller() - expect(spy.secondCall).to.have.been.calledWith(args) - }); - }) From e46f8d588140d035c45b32a754636d2e600f7832 Mon Sep 17 00:00:00 2001 From: ludbek Date: Mon, 11 Jul 2016 20:56:39 +0545 Subject: [PATCH 3/3] fixed syntax error --- test/mithril.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mithril.js b/test/mithril.js index c87bc142..1e9cbcfa 100644 --- a/test/mithril.js +++ b/test/mithril.js @@ -223,6 +223,6 @@ describe("m()", function () { var args = {age: 12} - expect(m.bind(m, component, args).to.throw(); + expect(m.bind(m, component, args)).to.throw() }) })