proper component check at m()

This commit is contained in:
ludbek 2016-07-11 10:55:30 +05:45
parent 03c6188989
commit 8d14e811f9
2 changed files with 29 additions and 1 deletions

View file

@ -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 " +

View file

@ -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)
});
})