diff --git a/test-deps/mock.js b/test-deps/mock.js index 9d6f2131..a54a222b 100644 --- a/test-deps/mock.js +++ b/test-deps/mock.js @@ -45,6 +45,9 @@ window.mock = (function () { "use strict" var window = {} + + window.window = window + var document = window.document = { // FIXME: add document.createRange().createContextualFragment() @@ -136,7 +139,7 @@ window.mock = (function () { name = name.toLowerCase() var out = [] - function traverse(node){ + function traverse(node) { if (node.childNodes && node.childNodes.length > 0) { node.childNodes.forEach(function (curr) { if (curr.nodeName.toLowerCase() === name) { @@ -156,7 +159,7 @@ window.mock = (function () { window.scrollTo = function () {} - ;(function (window) { + ;(function () { // This is an actual conforming implementation of the // requestAnimationFrame spec, with the nonstandard extension of // rAF.$resolve for running the callbacks. It works in Node and the @@ -212,7 +215,7 @@ window.mock = (function () { } window.requestAnimationFrame = requestAnimationFrame - })(window) + })() window.XMLHttpRequest = (function () { function Request() { diff --git a/test/isolation-test.html b/test/isolation-test.html new file mode 100644 index 00000000..d566c810 --- /dev/null +++ b/test/isolation-test.html @@ -0,0 +1,8 @@ + + + + + + +

Open the console to see the test report

+ diff --git a/test/isolation-test.js b/test/isolation-test.js new file mode 100644 index 00000000..80f89f66 --- /dev/null +++ b/test/isolation-test.js @@ -0,0 +1,159 @@ +/* global m, test, mock */ +(function () { + "use strict" + + m.deps(mock.window) + + test(function () { // eslint-disable-line max-statements + var root = mock.document.createElement("div") + var retain = false + var flag = true + var loaded1 = null + var loaded2 = null + var loaded1a = null + var loaded2a = null + + var Comp1 = { + controller: function () { + loaded1 = true + this.onunload = function () { + loaded1 = false + } + }, + view: function () { + if (retain) { + return {subtree: "retain"} + } else { + return m("a", { + config: function (el, init, ctx) { + if (!init) { + loaded1a = true + ctx.onunload = function () { + loaded1a = false + } + } + } + }) + } + } + } + + var Comp2 = { + controller: function () { + loaded2 = true + this.onunload = function () { + loaded2 = false + } + }, + view: function () { + if (retain) { + return {subtree: "retain"} + } else { + return m("b", { + config: function (el, init, ctx) { + if (!init) { + loaded2a = true + ctx.onunload = function () { + loaded2a = false + } + } + } + }) + } + } + } + + var Root = { + view: function () { + return flag ? Comp1 : Comp2 + } + } + + m.mount(root, Root) + + mock.requestAnimationFrame.$resolve() + + // loaded 1 + var result1 = loaded1 === true && + loaded2 === null && + loaded1a === true && + loaded2a === null + + retain = true + m.redraw(true) + mock.requestAnimationFrame.$resolve() + + // retained + var result2 = loaded1 === true && + loaded2 === null && + loaded1a === true && + loaded2a === null + + flag = false + m.redraw(true) + mock.requestAnimationFrame.$resolve() + + // loaded 2 while retained: both controllers are alive at the same time + // because dom element is retained + var result3 = loaded1 === true && + loaded2 === true && + loaded1a === true && + loaded2a === null + + retain = false + m.redraw(true) + mock.requestAnimationFrame.$resolve() + + // unretained, i.e. 2 is now dynamic + var result4 = loaded1 === false && + loaded2 === true && + loaded1a === false && + loaded2a === true + + flag = true + m.redraw(true) + mock.requestAnimationFrame.$resolve() + + // loaded 1 while dynamic + var result5 = loaded1 === true && + loaded2 === false && + loaded1a === true && + loaded2a === false + + return result1 && result2 && result3 && result4 && result5 + }) + + /* + test(function() { + var root = mock.document.createElement("div") + var redraws = 0, data + var Root = { + view: function() { + return Comp + } + } + + var Comp = { + controller: function() { + this.foo = m.request({method: "GET", url: "/foo"}) + }, + view: function(ctrl) { + redraws++ + data = ctrl.foo() + return m("div") + } + } + + m.mount(root, Root) + + mock.requestAnimationFrame.$resolve() + mock.XMLHttpRequest.$instances.pop().onreadystatechange() + + return redraws == 1 && data.url == "/foo" + }) + */ + + test.print(function (value) { + console.log(value) // eslint-disable-line no-console + }) +})() diff --git a/tests/index.html b/tests/index.html index f1e4baee..9d7f08f4 100644 --- a/tests/index.html +++ b/tests/index.html @@ -5,4 +5,4 @@ -

Open the console to see the test report

\ No newline at end of file +

Open the console to see the test report

diff --git a/tests/input-cursor.html b/tests/input-cursor.html deleted file mode 100644 index 8611e06e..00000000 --- a/tests/input-cursor.html +++ /dev/null @@ -1,48 +0,0 @@ -

Typing in the fields below should not move the cursor to the end of the input. Especially in Chrome

-

All inputs should update with the same value

-

Typing in an input should not prevent it from being updated by other inputs

-
- - diff --git a/tests/isolation-test.html b/tests/isolation-test.html deleted file mode 100644 index 210d2693..00000000 --- a/tests/isolation-test.html +++ /dev/null @@ -1,135 +0,0 @@ - - - - - - -

Open the console to see the test report

- \ No newline at end of file diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index 06fda631..db28436d 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -1,57 +1,127 @@ -function testMithril(mock) { - m.deps(mock) +/* global m, test, mock */ +(function () { // eslint-disable-line max-statements + "use strict" - //m - test(function() {return m.version().constructor === String}) - test(function() {return m("div").tag === "div"}) - test(function() {return m(".foo").tag === "div"}) - test(function() {return m(".foo").attrs.className === "foo"}) - test(function() {return m("[title=bar]").tag === "div"}) - test(function() {return m("[title=bar]").attrs.title === "bar"}) - test(function() {return m("[title=\'bar\']").attrs.title === "bar"}) - test(function() {return m("[title=\"bar\"]").attrs.title === "bar"}) - test(function() {return m("div", "test").children[0] === "test"}) - test(function() {return m("div", "test", "test2").children[1] === "test2"}) - test(function() {return m("div", ["test"]).children[0] === "test"}) - test(function() {return m("div", {title: "bar"}, "test").attrs.title === "bar"}) - test(function() {return m("div", {title: "bar"}, "test").children[0] === "test"}) - test(function() {return m("div", {title: "bar"}, ["test"]).children[0] === "test"}) - test(function() {return m("div", {title: "bar"}, m("div")).children[0].tag === "div"}) - test(function() {return m("div", {title: "bar"}, [m("div")]).children[0].tag === "div"}) - test(function() {return m("div", {title: "bar"}, "test0", "test1", "test2", "test3").children[3] === "test3"}) // splat - test(function() {return m("div", {title: "bar"}, m("div"), m("i"), m("span")).children[2].tag === "span"}) - test(function() {return m("div", ["a", "b"]).children.length === 2}) - test(function() {return m("div", [m("div")]).children[0].tag === "div"}) - test(function() {return m("div", m("div")).children[0].tag === "div"}) //yes, this is expected behavior: see method signature - test(function() {return m("div", [undefined]).tag === "div"}) - test(function() {return m("div", [{foo: "bar"}])}) //as long as it doesn't throw errors, it's fine - test(function() {return m("svg", [m("g")])}) - test(function() {return m("svg", [m("a[href='http://google.com']")])}) - test(function() {return m(".foo", {"class": "bar"}).attrs["class"] === "foo bar"}) - test(function() {return m(".foo", {className: "bar"}).attrs.className === "foo bar"}) - test(function() {return m(".foo", {className: ""}).attrs.className === "foo"}) - test(function() {return m("div", {className: ""}).attrs.className === ""}) //https://github.com/lhorie/mithril.js/issues/382 and 512 - test(function() {return m("div", {"class": ""}).attrs.className === undefined}) - test(function() {return m("div", {className: ""}).attrs["class"] === undefined}) - test(function() {return m("div", {"class": ""}).attrs["class"] === ""}) - test(function() {return m("div", [1, 2, 3], 4).children.length === 2}) - test(function() {return m("div", [1, 2, 3], 4).children[0].length === 3}) - test(function() {return m("div", [1, 2, 3], 4).children[1] === 4}) - test(function() {return m("div", [1, 2, 3]).children.length === 3}) - test(function() {return m("div", [1, 2, 3], [4, 5, 6, 7]).children.length === 2}) - test(function() {return m("div", [1, 2, 3], [4, 5, 6, 7]).children[0].length === 3}) - test(function() {return m("div", [1, 2, 3], [4, 5, 6, 7]).children[1].length === 4}) - test(function() {return m("div", [1], [2], [3]).children.length === 3}) - test(function() { - //class changes shouldn't trigger dom recreation - var v1 = m(".foo", {"class": "", onclick: function() {}}) - var v2 = m(".foo", {"class": "bar", onclick: function() {}}) + m.deps(mock.window) + + // m + test(function () { return typeof m.version() === "string" }) + test(function () { return m("div").tag === "div" }) + test(function () { return m(".foo").tag === "div" }) + test(function () { return m(".foo").attrs.className === "foo" }) + test(function () { return m("[title=bar]").tag === "div" }) + test(function () { return m("[title=bar]").attrs.title === "bar" }) + test(function () { return m("[title=\'bar\']").attrs.title === "bar" }) + test(function () { return m("[title=\"bar\"]").attrs.title === "bar" }) + test(function () { return m("div", "test").children[0] === "test" }) + + test(function () { + return m("div", "test", "test2").children[1] === "test2" + }) + + test(function () { return m("div", ["test"]).children[0] === "test" }) + + test(function () { + return m("div", {title: "bar"}, "test").attrs.title === "bar" + }) + + test(function () { + return m("div", {title: "bar"}, "test").children[0] === "test" + }) + + test(function () { + return m("div", {title: "bar"}, ["test"]).children[0] === "test" + }) + + test(function () { + return m("div", {title: "bar"}, m("div")).children[0].tag === "div" + }) + + test(function () { + return m("div", {title: "bar"}, [m("div")]).children[0].tag === "div" + }) + + // splat + test(function () { + var node = m("div", {title: "bar"}, "test0", "test1", "test2", "test3") + return node.children[3] === "test3" + }) + + test(function () { + var node = m("div", {title: "bar"}, m("div"), m("i"), m("span")) + return node.children[2].tag === "span" + }) + + test(function () { return m("div", ["a", "b"]).children.length === 2 }) + test(function () { return m("div", [m("div")]).children[0].tag === "div" }) + + // yes, this is expected behavior: see method signature + test(function () { return m("div", m("div")).children[0].tag === "div" }) + + test(function () { return m("div", [undefined]).tag === "div" }) + + // as long as it doesn't throw errors, it's fine + test(function () { return m("div", [{foo: "bar"}]) }) + + test(function () { return m("svg", [m("g")]) }) + test(function () { return m("svg", [m("a[href='http://google.com']")]) }) + + test(function () { + return m(".foo", {class: "bar"}).attrs.class === "foo bar" + }) + + test(function () { + return m(".foo", {className: "bar"}).attrs.className === "foo bar" + }) + + test(function () { + return m(".foo", {className: ""}).attrs.className === "foo" + }) + + // https://github.com/lhorie/mithril.js/issues/382 and 512 + test(function () { + return m("div", {className: ""}).attrs.className === "" + }) + + test(function () { + return m("div", {class: ""}).attrs.className === undefined + }) + + test(function () { + return m("div", {className: ""}).attrs.class === undefined + }) + + test(function () { return m("div", {class: ""}).attrs.class === "" }) + test(function () { return m("div", [1, 2, 3], 4).children.length === 2 }) + test(function () { return m("div", [1, 2, 3], 4).children[0].length === 3 }) + test(function () { return m("div", [1, 2, 3], 4).children[1] === 4 }) + test(function () { return m("div", [1, 2, 3]).children.length === 3 }) + + test(function () { + return m("div", [1, 2, 3], [4, 5, 6, 7]).children.length === 2 + }) + + test(function () { + return m("div", [1, 2, 3], [4, 5, 6, 7]).children[0].length === 3 + }) + + test(function () { + return m("div", [1, 2, 3], [4, 5, 6, 7]).children[1].length === 4 + }) + + test(function () { return m("div", [1], [2], [3]).children.length === 3 }) + + test(function () { + // class changes shouldn't trigger dom recreation + var v1 = m(".foo", {class: "", onclick: function () {}}) + var v2 = m(".foo", {class: "bar", onclick: function () {}}) return Object.keys(v1.attrs).join() === Object.keys(v2.attrs).join() }) - test(function() { - //m should proxy object first arg to m.component + + test(function () { + // m should proxy object first arg to m.component var component = { - controller: function(args) { + controller: function (args) { this.args = args }, view: function () { @@ -65,16 +135,16 @@ function testMithril(mock) { return c1.args === args && c1.args === c2.args }) - //m.mount - test(function() { + // m.mount + test(function () { var root = mock.document.createElement("div") var whatever = 1 var app = { - view: function() { + view: function () { return [ - whatever % 2 ? m('span', '% 2') : undefined, - m('div', 'bugs'), - m('a') + whatever % 2 ? m("span", "% 2") : undefined, + m("div", "bugs"), + m("a") ] } } @@ -91,39 +161,44 @@ function testMithril(mock) { return root.childNodes.length }) - test(function() { + + test(function () { mock.requestAnimationFrame.$resolve() var root1 = mock.document.createElement("div") var mod1 = m.mount(root1, { - controller: function() {this.value = "test1"}, - view: function(ctrl) {return ctrl.value} + controller: function () { this.value = "test1" }, + view: function (ctrl) { return ctrl.value } }) var root2 = mock.document.createElement("div") var mod2 = m.mount(root2, { - controller: function() {this.value = "test2"}, - view: function(ctrl) {return ctrl.value} + controller: function () { this.value = "test2" }, + view: function (ctrl) { return ctrl.value } }) mock.requestAnimationFrame.$resolve() - return (root1.childNodes[0].nodeValue === "test1" && root2.childNodes[0].nodeValue === "test2") - && (mod1.value && mod1.value === "test1") && (mod2.value && mod2.value === "test2") + return (root1.childNodes[0].nodeValue === "test1" && + root2.childNodes[0].nodeValue === "test2") && + (mod1.value && mod1.value === "test1") && + (mod2.value && mod2.value === "test2") }) - test(function() { + + test(function () { mock.requestAnimationFrame.$resolve() var root = mock.document.createElement("div") var unloaded = false + m.mount(root, { - controller: function() { + controller: function () { this.value = "test1" - this.onunload = function() { + this.onunload = function () { unloaded = true } }, - view: function(ctrl) {return ctrl.value} + view: function (ctrl) { return ctrl.value } }) mock.requestAnimationFrame.$resolve() @@ -134,15 +209,16 @@ function testMithril(mock) { return unloaded }) - test(function() { - //component should pass args to both controller and view + + test(function () { + // component should pass args to both controller and view mock.requestAnimationFrame.$resolve() var root = mock.document.createElement("div") var slot1, slot2 var component = { - controller: function(options) {slot1 = options.a}, - view: function(ctrl, options) {slot2 = options.a} + controller: function (options) { slot1 = options.a }, + view: function (ctrl, options) { slot2 = options.a } } m.mount(root, m.component(component, {a: 1})) @@ -150,14 +226,15 @@ function testMithril(mock) { return slot1 === 1 && slot2 === 1 }) - test(function() { - //component should work without controller + + test(function () { + // component should work without controller mock.requestAnimationFrame.$resolve() var root = mock.document.createElement("div") var slot2 var component = { - view: function(ctrl, options) {slot2 = options.a} + view: function (ctrl, options) { slot2 = options.a } } m.mount(root, m.component(component, {a: 1})) @@ -165,26 +242,31 @@ function testMithril(mock) { return slot2 === 1 }) - test(function() { - //component controller should only run once + + test(function () { + // component controller should only run once mock.requestAnimationFrame.$resolve() var root = mock.document.createElement("div") - var count1 = 0, count2 = 0 - var component = { - view: function() { - return sub - } - } + var count1 = 0 + var count2 = 0 + var sub = { - controller: function() { + controller: function () { count1++ }, - view: function() { + view: function () { count2++ return m("div", "test") } } + + var component = { + view: function () { + return sub + } + } + m.mount(root, component) mock.requestAnimationFrame.$resolve() @@ -195,35 +277,43 @@ function testMithril(mock) { return count1 === 1 && count2 === 2 }) - test(function() { - //sub component controller should only run once + + test(function () { + // sub component controller should only run once mock.requestAnimationFrame.$resolve() var root = mock.document.createElement("div") - var count1 = 0, count2 = 0, count3 = 0, count4 = 0 - var component = { - view: function() { - return sub - } - } - var sub = { - controller: function() { - count1++ - }, - view: function() { - count2++ - return subsub - } - } + var count1 = 0 + var count2 = 0 + var count3 = 0 + var count4 = 0 + var subsub = { - controller: function() { + controller: function () { count3++ }, - view: function() { + view: function () { count4++ return m("div", "test") } } + + var sub = { + controller: function () { + count1++ + }, + view: function () { + count2++ + return subsub + } + } + + var component = { + view: function () { + return sub + } + } + m.mount(root, component) mock.requestAnimationFrame.$resolve() @@ -234,26 +324,30 @@ function testMithril(mock) { return count1 === 1 && count2 === 2 && count3 === 1 && count4 === 2 }) - test(function() { - //keys in components should work + + test(function () { + // keys in components should work mock.requestAnimationFrame.$resolve() var root = mock.document.createElement("div") var list = [1, 2, 3] - var component = { - controller: function() {}, - view: function() { - return list.map(function(i) { - return m.component(sub, {key: i}) - }) - } - } + var sub = { - controller: function() {}, - view: function() { + controller: function () {}, + view: function () { return m("div") } } + + var component = { + controller: function () {}, + view: function () { + return list.map(function (i) { + return m.component(sub, {key: i}) + }) + } + } + m.mount(root, component) var firstBefore = root.childNodes[0] @@ -269,107 +363,36 @@ function testMithril(mock) { return firstBefore === firstAfter }) - test(function() { - //keys in subcomponents should work + + test(function () { + // keys in subcomponents should work mock.requestAnimationFrame.$resolve() var root = mock.document.createElement("div") var list = [1, 2, 3] - var component = { - controller: function() {}, - view: function() { - return list.map(function(i) { - return m.component(sub, {key: i}) - }) - } - } - var sub = { - view: function() { - return subsub - } - } + var subsub = { - controller: function() {}, - view: function() { + controller: function () {}, + view: function () { return m("div") } } - m.mount(root, component) - var firstBefore = root.childNodes[0] - - mock.requestAnimationFrame.$resolve() - - list.reverse() - m.redraw(true) - - mock.requestAnimationFrame.$resolve() - - var firstAfter = root.childNodes[2] - - return firstBefore === firstAfter - }) - test(function() { - //keys in components should work even if component internally messes them up - mock.requestAnimationFrame.$resolve() - - var root = mock.document.createElement("div") - var list = [1, 2, 3] - var component = { - controller: function() {}, - view: function() { - return list.map(function(i) { - return m.component(sub, {key: i}) - }) - } - } var sub = { - controller: function() {}, - view: function() { - return m("div", {key: 1}) - } - } - m.mount(root, component) - - var firstBefore = root.childNodes[0] - - mock.requestAnimationFrame.$resolve() - - list.reverse() - m.redraw(true) - - mock.requestAnimationFrame.$resolve() - - var firstAfter = root.childNodes[2] - - return firstBefore === firstAfter - }) - test(function() { - //keys in subcomponents should work even if component internally messes them up - mock.requestAnimationFrame.$resolve() - - var root = mock.document.createElement("div") - var list = [1, 2, 3] - var component = { - controller: function() {}, - view: function() { - return list.map(function(i) { - return m.component(sub, {key: i}) - }) - } - } - var sub = { - controller: function() {}, - view: function() { + view: function () { return subsub } } - var subsub = { - controller: function() {}, - view: function() { - return m("div", {key: 1}) + + var component = { + controller: function () {}, + view: function () { + return list.map(function (i) { + return m.component(sub, {key: i}) + }) } } + m.mount(root, component) var firstBefore = root.childNodes[0] @@ -385,26 +408,118 @@ function testMithril(mock) { return firstBefore === firstAfter }) - test(function() { - //component identity should stay intact if components are descendants of keyed elements + + test(function () { + // keys in components should work even if component internally messes + // them up mock.requestAnimationFrame.$resolve() var root = mock.document.createElement("div") var list = [1, 2, 3] + + var sub = { + controller: function () {}, + view: function () { + return m("div", {key: 1}) + } + } + var component = { - controller: function() {}, - view: function() { - return list.map(function(i) { + controller: function () {}, + view: function () { + return list.map(function (i) { + return m.component(sub, {key: i}) + }) + } + } + + m.mount(root, component) + + var firstBefore = root.childNodes[0] + + mock.requestAnimationFrame.$resolve() + + list.reverse() + m.redraw(true) + + mock.requestAnimationFrame.$resolve() + + var firstAfter = root.childNodes[2] + + return firstBefore === firstAfter + }) + + test(function () { + // keys in subcomponents should work even if component internally messes + // them up + mock.requestAnimationFrame.$resolve() + + var root = mock.document.createElement("div") + var list = [1, 2, 3] + + var subsub = { + controller: function () {}, + view: function () { + return m("div", {key: 1}) + } + } + + var sub = { + controller: function () {}, + view: function () { + return subsub + } + } + + var component = { + controller: function () {}, + view: function () { + return list.map(function (i) { + return m.component(sub, {key: i}) + }) + } + } + + m.mount(root, component) + + var firstBefore = root.childNodes[0] + + mock.requestAnimationFrame.$resolve() + + list.reverse() + m.redraw(true) + + mock.requestAnimationFrame.$resolve() + + var firstAfter = root.childNodes[2] + + return firstBefore === firstAfter + }) + + test(function () { + // component identity should stay intact if components are descendants + // of keyed elements + mock.requestAnimationFrame.$resolve() + + var root = mock.document.createElement("div") + var list = [1, 2, 3] + + var sub = { + controller: function () {}, + view: function () { + return m("div") + } + } + + var component = { + controller: function () {}, + view: function () { + return list.map(function (i) { return m("div", {key: i}, sub) }) } } - var sub = { - controller: function() {}, - view: function() { - return m("div") - } - } + m.mount(root, component) var firstBefore = root.childNodes[0].childNodes[0] @@ -420,32 +535,38 @@ function testMithril(mock) { return firstBefore === firstAfter }) - test(function() { - //subcomponent identity should stay intact if components are descendants of keyed elements + + test(function () { + // subcomponent identity should stay intact if components are + // descendants of keyed elements mock.requestAnimationFrame.$resolve() var root = mock.document.createElement("div") var list = [1, 2, 3] + + var subsub = { + controller: function () {}, + view: function () { + return m("div") + } + } + + var sub = { + controller: function () {}, + view: function () { + return subsub + } + } + var component = { - controller: function() {}, - view: function() { - return list.map(function(i) { + controller: function () {}, + view: function () { + return list.map(function (i) { return m("div", {key: i}, sub) }) } } - var sub = { - controller: function() {}, - view: function() { - return subsub - } - } - var subsub = { - controller: function() {}, - view: function() { - return m("div") - } - } + m.mount(root, component) var firstBefore = root.childNodes[0].childNodes[0] @@ -461,31 +582,35 @@ function testMithril(mock) { return firstBefore === firstAfter }) - test(function() { - //component should call onunload when removed from template + + test(function () { + // component should call onunload when removed from template mock.requestAnimationFrame.$resolve() var root = mock.document.createElement("div") var list = [1, 2, 3] var unloaded + + var sub = { + controller: function (opts) { + this.onunload = function () { + unloaded = opts.key + } + }, + view: function () { + return m("div") + } + } + var component = { - controller: function() {}, - view: function() { - return list.map(function(i) { + controller: function () {}, + view: function () { + return list.map(function (i) { return m.component(sub, {key: i}) }) } } - var sub = { - controller: function(opts) { - this.onunload = function() { - unloaded = opts.key - } - }, - view: function() { - return m("div") - } - } + m.mount(root, component) mock.requestAnimationFrame.$resolve() @@ -497,41 +622,46 @@ function testMithril(mock) { return unloaded === 3 }) - test(function() { - //subcomponent should call onunload when removed from template + + test(function () { + // subcomponent should call onunload when removed from template mock.requestAnimationFrame.$resolve() var root = mock.document.createElement("div") var list = [1, 2, 3] var unloaded1, unloaded2 + + var subsub = { + controller: function (opts) { + this.onunload = function () { + unloaded2 = opts.key + } + }, + view: function () { + return m("div") + } + } + + var sub = { + controller: function (opts) { + this.onunload = function () { + unloaded1 = opts.key + } + }, + view: function (ctrl, opts) { + return m.component(subsub, {key: opts.key}) + } + } + var component = { - controller: function() {}, - view: function() { - return list.map(function(i) { + controller: function () {}, + view: function () { + return list.map(function (i) { return m.component(sub, {key: i}) }) } } - var sub = { - controller: function(opts) { - this.onunload = function() { - unloaded1 = opts.key - } - }, - view: function(ctrl, opts) { - return m.component(subsub, {key: opts.key}) - } - } - var subsub = { - controller: function(opts) { - this.onunload = function() { - unloaded2 = opts.key - } - }, - view: function() { - return m("div") - } - } + m.mount(root, component) mock.requestAnimationFrame.$resolve() @@ -543,91 +673,112 @@ function testMithril(mock) { return unloaded1 === 3 && unloaded2 === 3 }) - test(function() { - //calling m.redraw synchronously from controller constructor should not trigger extra redraws + + test(function () { + // calling m.redraw synchronously from controller constructor should not + // trigger extra redraws mock.requestAnimationFrame.$resolve() var root = mock.document.createElement("div") var count = 0 - var component = { - controller: function() {}, - view: function() { - return sub - } - } + var sub = { - controller: function() { + controller: function () { m.redraw() }, - view: function() { + view: function () { count++ return m("div") } } + + var component = { + controller: function () {}, + view: function () { + return sub + } + } + m.mount(root, component) mock.requestAnimationFrame.$resolve() return count === 1 }) - test(function() { - //calling m.redraw synchronously from controller constructor should not trigger extra redraws + + test(function () { + // calling m.redraw synchronously from controller constructor should not + // trigger extra redraws mock.requestAnimationFrame.$resolve() var root = mock.document.createElement("div") var count = 0 - var component = { - controller: function() {}, - view: function() { - return sub - } - } - var sub = { - controller: function() {}, - view: function() { - return subsub - } - } + var subsub = { - controller: function() { + controller: function () { m.redraw() }, - view: function() { + view: function () { count++ return m("div") } } + + var sub = { + controller: function () {}, + view: function () { + return subsub + } + } + + var component = { + controller: function () {}, + view: function () { + return sub + } + } + m.mount(root, component) mock.requestAnimationFrame.$resolve() return count === 1 }) - test(function() { - //calling preventDefault from component's onunload should prevent route change + + test(function () { + // calling preventDefault from component's onunload should prevent route + // change mock.requestAnimationFrame.$resolve() mock.location.search = "?" var root = mock.document.createElement("div") var loaded = false var testEnabled = true - var component = { - controller: function() {}, - view: function() { - return sub - } - } + var sub = { - controller: function() { - this.onunload = function(e) {if (testEnabled) e.preventDefault()} + controller: function () { + this.onunload = function (e) { + if (testEnabled) e.preventDefault() + } }, - view: function() { + view: function () { return m("div") } } + + var component = { + controller: function () {}, + view: function () { + return sub + } + } + m.route(root, "/a", { "/a": component, - "/b": {controller: function() {loaded = true}, view: function() {}} + "/b": { + controller: function () { loaded = true }, + view: function () {} + } }) mock.requestAnimationFrame.$resolve() @@ -639,115 +790,147 @@ function testMithril(mock) { return loaded === false }) - test(function() { - //calling preventDefault from subcomponent's onunload should prevent route change + + test(function () { + // calling preventDefault from subcomponent's onunload should prevent + // route change mock.requestAnimationFrame.$resolve() mock.location.search = "?" var root = mock.document.createElement("div") var loaded = false var testEnabled = true - var component = { - controller: function() {}, - view: function() { - return sub + + var subsub = { + controller: function () { + this.onunload = function (e) { + if (testEnabled) e.preventDefault() + } + }, + view: function () { + return m("div") } } + var sub = { - controller: function() {}, - view: function() { + controller: function () {}, + view: function () { return subsub } } + + var component = { + controller: function () {}, + view: function () { + return sub + } + } + + m.route(root, "/a", { + "/a": component, + "/b": { + controller: function () { loaded = true }, + view: function () {} + } + }) + + mock.requestAnimationFrame.$resolve() + + m.route("/b") + + mock.requestAnimationFrame.$resolve() + testEnabled = false + + return loaded === false + }) + + test(function () { + // calling preventDefault from non-curried component's onunload should + // prevent route change + mock.requestAnimationFrame.$resolve() + mock.location.search = "?" + + var root = mock.document.createElement("div") + var loaded = false + var testEnabled = true + + var sub = { + controller: function () { + this.onunload = function (e) { + if (testEnabled) e.preventDefault() + } + }, + view: function () { + return m("div") + } + } + + var component = { + controller: function () {}, + view: function () { + return sub + } + } + + m.route(root, "/a", { + "/a": component, + "/b": { + controller: function () { loaded = true }, + view: function () {} + } + }) + + mock.requestAnimationFrame.$resolve() + + m.route("/b") + + mock.requestAnimationFrame.$resolve() + testEnabled = false + + return loaded === false + }) + + test(function () { + // calling preventDefault from non-curried subcomponent's onunload + // should prevent route change + mock.requestAnimationFrame.$resolve() + mock.location.search = "?" + + var root = mock.document.createElement("div") + var loaded = false + var testEnabled = true + var subsub = { - controller: function() { - this.onunload = function(e) {if (testEnabled) e.preventDefault()} + controller: function () { + this.onunload = function (e) { + if (testEnabled) e.preventDefault() + } }, - view: function() { + view: function () { return m("div") } } - m.route(root, "/a", { - "/a": component, - "/b": {controller: function() {loaded = true}, view: function() {}} - }) - mock.requestAnimationFrame.$resolve() - - m.route("/b") - - mock.requestAnimationFrame.$resolve() - testEnabled = false - - return loaded === false - }) - test(function() { - //calling preventDefault from non-curried component's onunload should prevent route change - mock.requestAnimationFrame.$resolve() - mock.location.search = "?" - - var root = mock.document.createElement("div") - var loaded = false - var testEnabled = true - var component = { - controller: function() {}, - view: function() { - return sub - } - } var sub = { - controller: function() { - this.onunload = function(e) {if (testEnabled) e.preventDefault()} - }, - view: function() { - return m("div") - } - } - m.route(root, "/a", { - "/a": component, - "/b": {controller: function() {loaded = true}, view: function() {}} - }) - - mock.requestAnimationFrame.$resolve() - - m.route("/b") - - mock.requestAnimationFrame.$resolve() - testEnabled = false - - return loaded === false - }) - test(function() { - //calling preventDefault from non-curried subcomponent's onunload should prevent route change - mock.requestAnimationFrame.$resolve() - mock.location.search = "?" - - var root = mock.document.createElement("div") - var loaded = false - var testEnabled = true - var component = { - controller: function() {}, - view: function() { - return sub - } - } - var sub = { - controller: function() {}, - view: function() { + controller: function () {}, + view: function () { return subsub } } - var subsub = { - controller: function() { - this.onunload = function(e) {if (testEnabled) e.preventDefault()} - }, - view: function() { - return m("div") + + var component = { + controller: function () {}, + view: function () { + return sub } } + m.route(root, "/a", { "/a": component, - "/b": {controller: function() {loaded = true}, view: function() {}} + "/b": { + controller: function () { loaded = true }, + view: function () {} + } }) mock.requestAnimationFrame.$resolve() @@ -759,44 +942,50 @@ function testMithril(mock) { return loaded === false }) - test(function() { + + test(function () { // nested components under keyed components should render mock.requestAnimationFrame.$resolve() var root = mock.document.createElement("div") var count = 0 - var App = { - controller: function() {}, - view: function() { - return m('.outer', [ - m('.inner', m.component(CommentList, { list: [1, 2, 3] })) - ]) + + var Reply = { + controller: function () {}, + view: function () { + count++ + return m(".reply") } } + var CommentList = { - controller: function() {}, - view: function(ctrl, props) { - return m('.list', props.list.map(function(i) { - return m('.comment', [ + controller: function () {}, + view: function (ctrl, props) { + return m(".list", props.list.map(function (i) { + return m(".comment", [ m.component(Reply, {key: i}) ]) })) } } - var Reply = { - controller: function() {}, - view: function() { - count++ - return m(".reply") + + var App = { + controller: function () {}, + view: function () { + return m(".outer", [ + m(".inner", m.component(CommentList, {list: [1, 2, 3]})) + ]) } } + m.mount(root, App) mock.requestAnimationFrame.$resolve() return count === 3 }) - test(function() { + + test(function () { // a route change should initialize a component's controller mock.requestAnimationFrame.$resolve() mock.location.search = "?" @@ -805,25 +994,25 @@ function testMithril(mock) { var countA = 0 var countB = 0 var subA = { - controller: function(){ countA += 1 }, - view: function() { return m("div") } + controller: function (){ countA += 1 }, + view: function () { return m("div") } } var subB = { - controller: function() { countB += 1 }, - view: function() { return m("div") } + controller: function () { countB += 1 }, + view: function () { return m("div") } } m.route(root, "/a", { "/a": { view: function () { - return m('.page-a', [ - m('h1'), m.component(subA, { x: 11 }) + return m(".page-a", [ + m("h1"), m.component(subA, {x: 11}) ]) } }, "/b": { - view: function() { - return m('.page-b', [ - m('h2'), m.component(subB, { y: 22 }) + view: function () { + return m(".page-b", [ + m("h2"), m.component(subB, {y: 22}) ]) } } @@ -841,28 +1030,33 @@ function testMithril(mock) { return countA === 2 && countB === 1 }) - test(function() { + + test(function () { var root = mock.document.createElement("div") - var component = {}, unloaded = false - component.controller = function() { - this.onunload = function() {unloaded = true} + var component = {} + var unloaded = false + component.controller = function () { + this.onunload = function () { unloaded = true } } - component.view = function() {} + component.view = function () {} m.mount(root, component) - m.mount(root, {controller: function() {}, view: function() {}}) + m.mount(root, {controller: function () {}, view: function () {}}) return unloaded === true }) - test(function() { + + test(function () { mock.requestAnimationFrame.$resolve() var root = mock.document.createElement("div") var initCount = 0 var component = {} - component.view = function() { - return m("div", {config: function(el, init) { - if (!init) initCount++ - }}) + component.view = function () { + return m("div", { + config: function (el, init) { + if (!init) initCount++ + } + }) } m.mount(root, component) @@ -874,7 +1068,8 @@ function testMithril(mock) { return initCount === 1 }) - test(function() { + + test(function () { var root = mock.document.createElement("div") var dom = mock.document.createElement("div") @@ -882,9 +1077,13 @@ function testMithril(mock) { var show = true var component = { - view: function() { + view: function () { return [ - m(".foo", {key: 1, config: test, onclick: function() {show = !show}}), + m(".foo", { + key: 1, + config: test, + onclick: function () { show = !show } + }), show ? m(".bar", {key: 2}) : null ] } @@ -912,28 +1111,29 @@ function testMithril(mock) { return root.childNodes.length === 3 }) - test(function() { + + test(function () { var root = mock.document.createElement("div") var show = true var testcomponent = { - controller: function() {}, - view: function() { - return m('div', 'component'); + controller: function () {}, + view: function () { + return m("div", "component") } } var app = { - view: function() { + view: function () { return show ? [ - m('h1', '1'), + m("h1", "1"), testcomponent ] : [ - m('h1', '2') - ]; + m("h1", "2") + ] } - }; + } - m.mount(root, app); + m.mount(root, app) mock.requestAnimationFrame.$resolve() @@ -949,14 +1149,15 @@ function testMithril(mock) { return root.childNodes.length === 2 }) - test(function() { + + test(function () { // Components should not require a view mock.requestAnimationFrame.$resolve() mock.location.search = "?" var Component = { view: function () { - return m('.comp') + return m(".comp") } } @@ -964,8 +1165,8 @@ function testMithril(mock) { m.route.mode = "search" m.route(root, "/foo", { "/foo": { - view: function() { - return [ Component ] + view: function () { + return [Component] } } }) @@ -974,34 +1175,41 @@ function testMithril(mock) { return root.childNodes[0].nodeName === "DIV" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/551 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/551 var root = mock.document.createElement("div") - var a = false, found = false, unloaded = false, redraws = 0 - var Root = { - view: function() { - return Comp - } - } + var a = false + var found = false + var unloaded = false + var redraws = 0 + var Comp = { - view: function() { + view: function () { redraws++ return m("div", {config: Comp.config}, [ - m("div", {onclick: function() { - a = !a - m.redraw(true) - found = root.childNodes[0].childNodes[1] - }}, "asd"), + m("div", { + onclick: function () { + a = !a + m.redraw(true) + found = root.childNodes[0].childNodes[1] + } + }, "asd"), a ? m("#a", "aaa") : null, "test" ]) }, - config: function(el, init, ctx) { - if (!init) ctx.onunload = function() { - unloaded = true - } + config: function (el, init, ctx) { + if (!init) ctx.onunload = function () { unloaded = true } } } + + var Root = { + view: function () { + return Comp + } + } + m.mount(root, Root) var target = root.childNodes[0].childNodes[0] @@ -1011,35 +1219,42 @@ function testMithril(mock) { return !unloaded && found.id === "a" && redraws === 3 }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/551 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/551 var root = mock.document.createElement("div") - var a = false, found = false, unloaded = false, redraws = 0 - var Root = { - view: function() { - return Comp - } - } + var a = false + var found = false + var unloaded = false + var redraws = 0 + var Comp = { - view: function() { + view: function () { redraws++ return m("div", {config: Comp.config}, [ - m("div", {onclick: function() { - a = !a - m.redraw(true) - found = root.childNodes[0].childNodes[1] - m.redraw.strategy("none") - }}, "asd"), + m("div", { + onclick: function () { + a = !a + m.redraw(true) + found = root.childNodes[0].childNodes[1] + m.redraw.strategy("none") + } + }, "asd"), a ? m("#a", "aaa") : null, "test" ]) }, - config: function(el, init, ctx) { - if (!init) ctx.onunload = function() { - unloaded = true - } + config: function (el, init, ctx) { + if (!init) ctx.onunload = function () { unloaded = true } } } + + var Root = { + view: function () { + return Comp + } + } + m.mount(root, Root) var target = root.childNodes[0].childNodes[0] @@ -1049,13 +1264,14 @@ function testMithril(mock) { return !unloaded && found.id === "a" && redraws === 2 }) - test(function() { + + test(function () { var root = mock.document.createElement("div") var redraws = 0 var Root = { - view: function() { + view: function () { redraws++ - return m("div", {onclick: function() {m.redraw(true)}}) + return m("div", {onclick: function () { m.redraw(true) }}) } } @@ -1068,38 +1284,43 @@ function testMithril(mock) { return redraws === 3 }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/555 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/555 var root = mock.document.createElement("div") + var MyComponent = { - controller: function(args) { - this.name = args.name; + controller: function (args) { + this.name = args.name }, - view: function(ctrl) { - return m('div', ctrl.name); + view: function (ctrl) { + return m("div", ctrl.name) } } + var FooPage = { - view: function() { - return m('div', [ - m('a[href=/]', {config: m.route}, 'foo'), - m('a[href=/bar]', {config: m.route}, 'bar'), - m.component(MyComponent, {name: 'Jane'}) - ]); + view: function () { + return m("div", [ + m("a[href=/]", {config: m.route}, "foo"), + m("a[href=/bar]", {config: m.route}, "bar"), + m.component(MyComponent, {name: "Jane"}) + ]) } - }; + } + var BarPage = { - view: function() { - return m('div', [ - m('a[href=/]', {config: m.route}, 'foo'), - m('a[href=/bar]', {config: m.route}, 'bar'), - m.component(MyComponent, {name: 'Bob'}) - ]); + view: function () { + return m("div", [ + m("a[href=/]", {config: m.route}, "foo"), + m("a[href=/bar]", {config: m.route}, "bar"), + m.component(MyComponent, {name: "Bob"}) + ]) } - }; - m.route(root, '/', { - '/': FooPage, - '/bar': BarPage + } + + m.route(root, "/", { + "/": FooPage, + "/bar": BarPage }) mock.requestAnimationFrame.$resolve() @@ -1108,28 +1329,32 @@ function testMithril(mock) { mock.requestAnimationFrame.$resolve() - return root.childNodes[0].childNodes[2].childNodes[0].nodeValue === "Bob" + var parent = root.childNodes[0].childNodes[2].childNodes[0] + return parent.nodeValue === "Bob" }) - test(function() { + + test(function () { var root = mock.document.createElement("div") - var redraws = 0, data - var Root = { - view: function() { - return Comp - } - } + var redraws = 0 + var data var Comp = { - controller: function() { + controller: function () { this.foo = m.request({method: "GET", url: "/foo"}) }, - view: function(ctrl) { + view: function (ctrl) { redraws++ data = ctrl.foo() return m("div") } } + var Root = { + view: function () { + return Comp + } + } + m.mount(root, Root) mock.requestAnimationFrame.$resolve() @@ -1141,39 +1366,41 @@ function testMithril(mock) { return redraws === 1 && data.url === "/foo" }) - test(function() { + + test(function () { mock.requestAnimationFrame.$resolve() mock.location.search = "?" var root = mock.document.createElement("div") - var redraws1 = 0, redraws2 = 0 - var Root = { - view: function() { - return m("div", [ - Comp1, - Comp2 - ]) - } - } + var redraws1 = 0 + var redraws2 = 0 + var Comp1 = { - controller: function() { + controller: function () { this.foo = m.request({method: "GET", url: "/foo"}) }, - view: function() { + view: function () { redraws1++ return m("div") } } + var Comp2 = { - controller: function() { + controller: function () { this.bar = m.request({method: "GET", url: "/bar"}) }, - view: function() { + view: function () { redraws2++ return m("div") } } + var Root = { + view: function () { + return m("div", [Comp1, Comp2]) + } + } + m.mount(root, Root) mock.requestAnimationFrame.$resolve() @@ -1188,38 +1415,43 @@ function testMithril(mock) { return redraws1 === 1 && redraws2 === 1 }) - test(function() { + + test(function () { var root = mock.document.createElement("div") - var redraws1 = 0, redraws2 = 0 - var Root1 = { - view: function() { - return Comp1 - } - } - var Root2 = { - view: function() { - return Comp2 - } - } + var redraws1 = 0 + var redraws2 = 0 + var Comp1 = { - controller: function() { + controller: function () { this.foo = m.request({method: "GET", url: "/foo"}) }, - view: function() { + view: function () { redraws1++ return m("div") } } + + var Root1 = { + view: function () { + return Comp1 + } + } + var Comp2 = { - controller: function() { + controller: function () { this.bar = m.request({method: "GET", url: "/bar"}) }, - view: function() { + view: function () { redraws2++ return m("div") } } + var Root2 = { + view: function () { + return Comp2 + } + } m.route(root, "/", { "/": Root1, @@ -1231,7 +1463,6 @@ function testMithril(mock) { m.route("/root2") - mock.requestAnimationFrame.$resolve() mock.XMLHttpRequest.$instances.pop().onreadystatechange() @@ -1241,30 +1472,34 @@ function testMithril(mock) { return redraws1 === 1 && redraws2 === 1 }) - test(function() { + + test(function () { var root = mock.document.createElement("div") var cond = true - var controller1 = null, controller2 = null - var Root = { - view: function() { - return cond ? Comp1 : Comp2 - } - } + var controller1 = null + var controller2 = null var Comp1 = { - view: function(ctrl) { + view: function (ctrl) { controller1 = ctrl return m("div") } } + var Comp2 = { - view: function(ctrl) { + view: function (ctrl) { controller2 = ctrl return m("div") } } + var Root = { + view: function () { + return cond ? Comp1 : Comp2 + } + } + m.mount(root, Root) mock.requestAnimationFrame.$resolve() @@ -1276,27 +1511,32 @@ function testMithril(mock) { return controller1 !== controller2 }) - test(function() { + + test(function () { var root = mock.document.createElement("div") var cond = true var unloaded = false - var Root = { - view: function() { - return cond ? Comp1 : Comp2 + + var Comp1 = { + view: function () { + return m("div", { + config: function (el, init, ctx) { + ctx.onunload = function () { unloaded = true } + } + }) } } - var Comp1 = { - view: function() { - return m("div", {config: function(el, init, ctx) { - ctx.onunload = function() {unloaded = true} - }}) + var Comp2 = { + view: function () { + return m("div") } } - var Comp2 = { - view: function() { - return m("div") + + var Root = { + view: function () { + return cond ? Comp1 : Comp2 } } @@ -1311,27 +1551,30 @@ function testMithril(mock) { return unloaded }) - test(function() { + + test(function () { var root = mock.document.createElement("div") var cond = true var initialized = null - var Root = { - view: function() { - return cond ? Comp1 : Comp2 - } - } var Comp1 = { - view: function() { + view: function () { return m("div") } } + var Comp2 = { - view: function() { - return m("div", {config: function(el, init) { - initialized = init - }}) + view: function () { + return m("div", { + config: function (el, init) { initialized = init } + }) + } + } + + var Root = { + view: function () { + return cond ? Comp1 : Comp2 } } @@ -1346,75 +1589,91 @@ function testMithril(mock) { return initialized === false }) - test(function() { + + test(function () { var root = mock.document.createElement("div") var el - var FooPage = { - view: function(ctrl) { - return m('div', [ - m('button', {onclick: function() { - ctrl.bar = true; - m.redraw(true); - el = root.childNodes[0].childNodes[1] - }}, 'click me'), - ctrl.bar ? m.component(BarComponent) : '' - ]); - } - }; + var BarComponent = { - view: function() { - return m('#bar', 'test'); + view: function () { + return m("#bar", "test") } - }; - m.mount(root, FooPage); + } + + var FooPage = { + view: function (ctrl) { + return m("div", [ + m("button", { + onclick: function () { + ctrl.bar = true + m.redraw(true) + el = root.childNodes[0].childNodes[1] + } + }, "click me"), + ctrl.bar ? m.component(BarComponent) : "" + ]) + } + } + + m.mount(root, FooPage) root.childNodes[0].childNodes[0].onclick({}) return el.id === "bar" }) - //m.withAttr - test(function() { - //the handler is called with the correct value & context when callbackThis not given - var _this = {}; - var value, context; - var handler = m.withAttr("test", function(data) { - value = data; - context = this; - }); - handler.call(_this, {currentTarget: {test: "foo"}}); - return value === "foo" && context === _this; - }) - test(function() { - //the handler is called with the correct value & context when callbackThis is given - var _this = {}; - var value, context; - var handler = m.withAttr("test", function(data) { - value = data; - context = this; - }, _this); - handler({currentTarget: {test: "foo"}}); - return value === "foo" && context === _this; + // m.withAttr + test(function () { + // the handler is called with the correct value & context when + // callbackThis not given + var _this = {} + var value, context + var handler = m.withAttr("test", function (data) { + value = data + /* eslint-disable consistent-this, no-invalid-this */ + context = this + /* eslint-enable consistent-this, no-invalid-this */ + }) + + handler.call(_this, {currentTarget: {test: "foo"}}) + return value === "foo" && context === _this }) - //m.trust - test(function() {return m.trust("test").valueOf() === "test"}) + test(function () { + // the handler is called with the correct value & context when + // callbackThis is given + var _this = {} + var value, context + var handler = m.withAttr("test", function (data) { + value = data + /* eslint-disable consistent-this, no-invalid-this */ + context = this + /* eslint-enable consistent-this, no-invalid-this */ + }, _this) + handler({currentTarget: {test: "foo"}}) + return value === "foo" && context === _this + }) - //m.render - test(function() { + // m.trust + test(function () { return m.trust("test").valueOf() === "test" }) + + // m.render + test(function () { var root = mock.document.createElement("div") m.render(root, "test") return root.childNodes[0].nodeValue === "test" }) - test(function() { + + test(function () { var root = mock.document.createElement("div") - m.render(root, m("div", {"class": "a"})) + m.render(root, m("div", {class: "a"})) var elementBefore = root.childNodes[0] - m.render(root, m("div", {"class": "b"})) + m.render(root, m("div", {class: "b"})) var elementAfter = root.childNodes[0] return elementBefore === elementAfter }) - test(function() { + + test(function () { var root = mock.document.createElement("div") m.render(root, m(".a")) var elementBefore = root.childNodes[0] @@ -1422,7 +1681,8 @@ function testMithril(mock) { var elementAfter = root.childNodes[0] return elementBefore === elementAfter }) - test(function() { + + test(function () { var root = mock.document.createElement("div") m.render(root, m("div", {id: "a"})) var elementBefore = root.childNodes[0] @@ -1430,7 +1690,8 @@ function testMithril(mock) { var elementAfter = root.childNodes[0] return elementBefore !== elementAfter }) - test(function() { + + test(function () { var root = mock.document.createElement("div") m.render(root, m("#a")) var elementBefore = root.childNodes[0] @@ -1438,7 +1699,8 @@ function testMithril(mock) { var elementAfter = root.childNodes[0] return elementBefore !== elementAfter }) - test(function() { + + test(function () { var root = mock.document.createElement("div") m.render(root, m("#a")) var elementBefore = root.childNodes[0] @@ -1446,202 +1708,287 @@ function testMithril(mock) { var elementAfter = root.childNodes[0] return elementBefore !== elementAfter }) - test(function() { + + test(function () { var root = mock.document.createElement("div") m.render(root, m("div", [undefined])) return root.childNodes[0].childNodes[0].nodeValue === "" }) - test(function() { + + test(function () { var root = mock.document.createElement("div") m.render(root, m("svg", [m("g")])) var g = root.childNodes[0].childNodes[0] - return g.nodeName === "G" && g.namespaceURI === "http://www.w3.org/2000/svg" + return g.nodeName === "G" && + g.namespaceURI === "http://www.w3.org/2000/svg" }) - test(function() { + + test(function () { var root = mock.document.createElement("div") m.render(root, m("svg", [m("a[href='http://google.com']")])) return root.childNodes[0].childNodes[0].nodeName === "A" }) - test(function() { + + test(function () { var root = mock.document.createElement("div") m.render(root, m("div.classname", [m("a", {href: "/first"})])) m.render(root, m("div", [m("a", {href: "/second"})])) return root.childNodes[0].childNodes.length === 1 }) - test(function() { + + test(function () { var root = mock.document.createElement("div") m.render(root, m("ul", [m("li")])) m.render(root, m("ul", [m("li"), undefined])) return root.childNodes[0].childNodes[1].nodeValue === "" }) - test(function() { + + test(function () { var root = mock.document.createElement("div") m.render(root, m("ul", [m("li"), m("li")])) m.render(root, m("ul", [m("li"), undefined])) return root.childNodes[0].childNodes[1].nodeValue === "" }) - test(function() { + + test(function () { var root = mock.document.createElement("div") m.render(root, m("ul", [m("li")])) m.render(root, m("ul", [undefined])) return root.childNodes[0].childNodes[0].nodeValue === "" }) - test(function() { + + test(function () { var root = mock.document.createElement("div") m.render(root, m("ul", [m("li")])) m.render(root, m("ul", [{}])) return root.childNodes[0].childNodes.length === 0 }) - test(function() { + + test(function () { var root = mock.document.createElement("div") m.render(root, m("ul", [m("li")])) m.render(root, m("ul", [{tag: "b", attrs: {}}])) return root.childNodes[0].childNodes[0].nodeName === "B" }) - test(function() { + + test(function () { var root = mock.document.createElement("div") m.render(root, m("ul", [m("li")])) + /* eslint-disable no-new-wrappers */ m.render(root, m("ul", [{tag: new String("b"), attrs: {}}])) + /* eslint-enable no-new-wrappers */ return root.childNodes[0].childNodes[0].nodeName === "B" }) - test(function() { + + test(function () { var root = mock.document.createElement("div") m.render(root, m("ul", [m("li", [m("a")])])) m.render(root, m("ul", [{subtree: "retain"}])) return root.childNodes[0].childNodes[0].childNodes[0].nodeName === "A" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/43 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/43 var root = mock.document.createElement("div") m.render(root, m("a", {config: m.route}, "test")) m.render(root, m("a", {config: m.route}, "test")) return root.childNodes[0].childNodes[0].nodeValue === "test" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/44 (1) + + test(function () { + // https://github.com/lhorie/mithril.js/issues/44 (1) var root = mock.document.createElement("div") m.render(root, m("#foo", [null, m("#bar")])) m.render(root, m("#foo", ["test", m("#bar")])) return root.childNodes[0].childNodes[0].nodeValue === "test" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/44 (2) + + test(function () { + // https://github.com/lhorie/mithril.js/issues/44 (2) var root = mock.document.createElement("div") m.render(root, m("#foo", [null, m("#bar")])) m.render(root, m("#foo", [m("div"), m("#bar")])) return root.childNodes[0].childNodes[0].nodeName === "DIV" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/44 (3) + + test(function () { + // https://github.com/lhorie/mithril.js/issues/44 (3) var root = mock.document.createElement("div") m.render(root, m("#foo", ["test", m("#bar")])) m.render(root, m("#foo", [m("div"), m("#bar")])) return root.childNodes[0].childNodes[0].nodeName === "DIV" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/44 (4) + + test(function () { + // https://github.com/lhorie/mithril.js/issues/44 (4) var root = mock.document.createElement("div") m.render(root, m("#foo", [m("div"), m("#bar")])) m.render(root, m("#foo", ["test", m("#bar")])) return root.childNodes[0].childNodes[0].nodeValue === "test" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/44 (5) + + test(function () { + // https://github.com/lhorie/mithril.js/issues/44 (5) var root = mock.document.createElement("div") m.render(root, m("#foo", [m("#bar")])) m.render(root, m("#foo", [m("#bar"), [m("#baz")]])) return root.childNodes[0].childNodes[1].id === "baz" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/48 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/48 var root = mock.document m.render(root, m("html", [m("#foo")])) var result = root.childNodes[0].childNodes[0].id === "foo" root.childNodes = [mock.document.createElement("html")] return result }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/49 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/49 var root = mock.document.createElement("div") m.render(root, m("a", "test")) m.render(root, m("a.foo", "test")) return root.childNodes[0].childNodes[0].nodeValue === "test" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/49 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/49 var root = mock.document.createElement("div") m.render(root, m("a.foo", "test")) m.render(root, m("a", "test")) return root.childNodes[0].childNodes[0].nodeValue === "test" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/49 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/49 var root = mock.document.createElement("div") m.render(root, m("a.foo", "test")) m.render(root, m("a", "test1")) return root.childNodes[0].childNodes[0].nodeValue === "test1" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/49 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/49 var root = mock.document.createElement("div") m.render(root, m("a", "test")) m.render(root, m("a", "test1")) return root.childNodes[0].childNodes[0].nodeValue === "test1" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/50 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/50 var root = mock.document.createElement("div") m.render(root, m("#foo", [[m("div", "a"), m("div", "b")], m("#bar")])) return root.childNodes[0].childNodes[1].childNodes[0].nodeValue === "b" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/50 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/50 var root = mock.document.createElement("div") - m.render(root, m("#foo", [[m("div", "a"), m("div", "b")], m("#bar")])) - m.render(root, m("#foo", [[m("div", "a"), m("div", "b"), m("div", "c")], m("#bar")])) + + m.render(root, m("#foo", [ + [m("div", "a"), m("div", "b")], + m("#bar") + ])) + + m.render(root, m("#foo", [ + [m("div", "a"), m("div", "b"), m("div", "c")], + m("#bar") + ])) + return root.childNodes[0].childNodes[2].childNodes[0].nodeValue === "c" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/50 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/50 var root = mock.document.createElement("div") - m.render(root, m("#foo", [[m("div", "a"), m("div", "b")], [m("div", "c"), m("div", "d")], m("#bar")])) - return root.childNodes[0].childNodes[3].childNodes[0].nodeValue === "d" && root.childNodes[0].childNodes[4].id === "bar" + + m.render(root, m("#foo", [ + [m("div", "a"), m("div", "b")], + [m("div", "c"), m("div", "d")], + m("#bar") + ])) + + var parent = root.childNodes[0] + return parent.childNodes[3].childNodes[0].nodeValue === "d" && + parent.childNodes[4].id === "bar" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/50 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/50 var root = mock.document.createElement("div") m.render(root, m("#foo", [[m("div", "a"), m("div", "b")], "test"])) - return root.childNodes[0].childNodes[1].childNodes[0].nodeValue === "b" && root.childNodes[0].childNodes[2].nodeValue === "test" + var parent = root.childNodes[0] + return parent.childNodes[1].childNodes[0].nodeValue === "b" && + parent.childNodes[2].nodeValue === "test" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/50 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/50 var root = mock.document.createElement("div") m.render(root, m("#foo", [["a", "b"], "test"])) - return root.childNodes[0].childNodes[1].nodeValue === "b" && root.childNodes[0].childNodes[2].nodeValue === "test" + var parent = root.childNodes[0] + return parent.childNodes[1].nodeValue === "b" && + parent.childNodes[2].nodeValue === "test" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/51 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/51 var root = mock.document.createElement("div") - m.render(root, m("main", [m("button"), m("article", [m("section"), m("nav")])])) - m.render(root, m("main", [m("button"), m("article", [m("span"), m("nav")])])) - return root.childNodes[0].childNodes[1].childNodes[0].nodeName === "SPAN" + + m.render(root, m("main", [ + m("button"), + m("article", [m("section"), m("nav")]) + ])) + + m.render(root, m("main", [ + m("button"), + m("article", [m("span"), m("nav")]) + ])) + + var node = root.childNodes[0].childNodes[1].childNodes[0] + return node.nodeName === "SPAN" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/51 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/51 var root = mock.document.createElement("div") - m.render(root, m("main", [m("button"), m("article", [m("section"), m("nav")])])) - m.render(root, m("main", [m("button"), m("article", ["test", m("nav")])])) - return root.childNodes[0].childNodes[1].childNodes[0].nodeValue === "test" + + m.render(root, m("main", [ + m("button"), + m("article", [m("section"), m("nav")]) + ])) + + m.render(root, m("main", [ + m("button"), + m("article", ["test", m("nav")]) + ])) + + var node = root.childNodes[0].childNodes[1].childNodes[0] + return node.nodeValue === "test" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/51 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/51 var root = mock.document.createElement("div") - m.render(root, m("main", [m("button"), m("article", [m("section"), m("nav")])])) - m.render(root, m("main", [m("button"), m("article", [m.trust("test"), m("nav")])])) - return root.childNodes[0].childNodes[1].childNodes[0].nodeValue === "test" + + m.render(root, m("main", [ + m("button"), + m("article", [m("section"), m("nav")]) + ])) + + m.render(root, m("main", [ + m("button"), + m("article", [m.trust("test"), m("nav")]) + ])) + + var node = root.childNodes[0].childNodes[1].childNodes[0] + return node.nodeValue === "test" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/55 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/55 var root = mock.document.createElement("div") m.render(root, m("#a")) var elementBefore = root.childNodes[0] @@ -1649,20 +1996,23 @@ function testMithril(mock) { var elementAfter = root.childNodes[0] return elementBefore !== elementAfter }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/56 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/56 var root = mock.document.createElement("div") m.render(root, [null, "foo"]) m.render(root, ["bar"]) return root.childNodes.length === 1 }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/56 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/56 var root = mock.document.createElement("div") m.render(root, m("div", "foo")) return root.childNodes.length === 1 }) - test(function() { + + test(function () { var root = mock.document.createElement("div") m.render(root, m("div", [m("button"), m("ul")])) var valueBefore = root.childNodes[0].childNodes[0].nodeName @@ -1670,7 +2020,8 @@ function testMithril(mock) { var valueAfter = root.childNodes[0].childNodes[0].nodeValue return valueBefore === "BUTTON" && valueAfter === "" }) - test(function() { + + test(function () { var root = mock.document.createElement("div") m.render(root, m("div", [m("ul"), undefined])) var valueBefore1 = root.childNodes[0].childNodes[0].nodeName @@ -1678,10 +2029,12 @@ function testMithril(mock) { m.render(root, m("div", [undefined, m("ul")])) var valueAfter1 = root.childNodes[0].childNodes[0].nodeValue var valueAfter2 = root.childNodes[0].childNodes[1].nodeName - return valueBefore1 === "UL" && valueAfter1 === "" && valueBefore2 === "" && valueAfter2 === "UL" + return valueBefore1 === "UL" && valueAfter1 === "" && + valueBefore2 === "" && valueAfter2 === "UL" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/79 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/79 var root = mock.document.createElement("div") m.render(root, m("div", {style: {background: "red"}})) var valueBefore = root.childNodes[0].style.background @@ -1689,12 +2042,14 @@ function testMithril(mock) { var valueAfter = root.childNodes[0].style.background return valueBefore === "red" && valueAfter === "" }) - test(function() { + + test(function () { var root = mock.document.createElement("div") m.render(root, m("div[style='background:red']")) return root.childNodes[0].style === "background:red" }) - test(function() { + + test(function () { var root = mock.document.createElement("div") m.render(root, m("div", {style: {background: "red"}})) var valueBefore = root.childNodes[0].style.background @@ -1702,219 +2057,398 @@ function testMithril(mock) { var valueAfter = root.childNodes[0].style.background return valueBefore === "red" && valueAfter === undefined }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/87 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/87 var root = mock.document.createElement("div") m.render(root, m("div", [[m("a"), m("a")], m("button")])) m.render(root, m("div", [[m("a")], m("button")])) - return root.childNodes[0].childNodes.length === 2 && root.childNodes[0].childNodes[1].nodeName === "BUTTON" + return root.childNodes[0].childNodes.length === 2 && + root.childNodes[0].childNodes[1].nodeName === "BUTTON" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/87 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/87 var root = mock.document.createElement("div") m.render(root, m("div", [m("a"), m("b"), m("button")])) m.render(root, m("div", [m("a"), m("button")])) - return root.childNodes[0].childNodes.length === 2 && root.childNodes[0].childNodes[1].nodeName === "BUTTON" + return root.childNodes[0].childNodes.length === 2 && + root.childNodes[0].childNodes[1].nodeName === "BUTTON" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/99 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/99 var root = mock.document.createElement("div") m.render(root, m("div", [m("img"), m("h1")])) m.render(root, m("div", [m("a")])) - return root.childNodes[0].childNodes.length === 1 && root.childNodes[0].childNodes[0].nodeName === "A" + return root.childNodes[0].childNodes.length === 1 && + root.childNodes[0].childNodes[0].nodeName === "A" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/120 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/120 var root = mock.document.createElement("div") m.render(root, m("div", ["a", "b", "c", "d"])) m.render(root, m("div", [["d", "e"]])) var children = root.childNodes[0].childNodes - return children.length === 2 && children[0].nodeValue === "d" && children[1].nodeValue === "e" + return children.length === 2 && + children[0].nodeValue === "d" && + children[1].nodeValue === "e" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/120 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/120 var root = mock.document.createElement("div") m.render(root, m("div", [["a", "b", "c", "d"]])) m.render(root, m("div", ["d", "e"])) var children = root.childNodes[0].childNodes - return children.length === 2 && children[0].nodeValue === "d" && children[1].nodeValue === "e" + return children.length === 2 && + children[0].nodeValue === "d" && + children[1].nodeValue === "e" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/120 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/120 var root = mock.document.createElement("div") m.render(root, m("div", ["x", [["a"], "b", "c", "d"]])) m.render(root, m("div", ["d", ["e"]])) var children = root.childNodes[0].childNodes - return children.length === 2 && children[0].nodeValue === "d" && children[1].nodeValue === "e" + return children.length === 2 && + children[0].nodeValue === "d" && + children[1].nodeValue === "e" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/120 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/120 var root = mock.document.createElement("div") m.render(root, m("div", ["b"])) m.render(root, m("div", [["e"]])) var children = root.childNodes[0].childNodes return children.length === 1 && children[0].nodeValue === "e" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/120 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/120 var root = mock.document.createElement("div") m.render(root, m("div", ["a", ["b"]])) m.render(root, m("div", ["d", [["e"]]])) var children = root.childNodes[0].childNodes - return children.length === 2 && children[0].nodeValue === "d" && children[1].nodeValue === "e" + return children.length === 2 && + children[0].nodeValue === "d" && + children[1].nodeValue === "e" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/120 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/120 var root = mock.document.createElement("div") m.render(root, m("div", ["a", [["b"]]])) m.render(root, m("div", ["d", ["e"]])) var children = root.childNodes[0].childNodes - return children.length === 2 && children[0].nodeValue === "d" && children[1].nodeValue === "e" + return children.length === 2 && + children[0].nodeValue === "d" && + children[1].nodeValue === "e" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/120 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/120 var root = mock.document.createElement("div") m.render(root, m("div", ["a", [["b"], "c"]])) m.render(root, m("div", ["d", [[["e"]], "x"]])) var children = root.childNodes[0].childNodes - return children.length === 3 && children[0].nodeValue === "d" && children[1].nodeValue === "e" + return children.length === 3 && + children[0].nodeValue === "d" && + children[1].nodeValue === "e" }) - test(function() { + + test(function () { var root = mock.document.createElement("div") var success = false - m.render(root, m("div", {config: function(elem, isInitialized, ctx) {ctx.data = 1}})) - m.render(root, m("div", {config: function(elem, isInitialized, ctx) {success = ctx.data === 1}})) + + m.render(root, m("div", { + config: function (elem, isInit, ctx) { ctx.data = 1 } + })) + + m.render(root, m("div", { + config: function (elem, isInit, ctx) { success = ctx.data === 1 } + })) + return success }) - test(function() { + + test(function () { var root = mock.document.createElement("div") - var index = 0; - var success = true; - var statefulConfig = function(elem, isInitialized, ctx) {ctx.data = index++} - var node = m("div", {config: statefulConfig}); - m.render(root, [node, node]); + var index = 0 + var success = true - index = 0; - var checkConfig = function(elem, isInitialized, ctx) { + function statefulConfig(elem, isInit, ctx) { ctx.data = index++ } + + var node = m("div", {config: statefulConfig}) + m.render(root, [node, node]) + + index = 0 + + function checkConfig(elem, isInit, ctx) { success = success && (ctx.data === index++) } - node = m("div", {config: checkConfig}); - m.render(root, [node, node]); - return success; + + node = m("div", {config: checkConfig}) + m.render(root, [node, node]) + return success }) - test(function() { + + test(function () { var root = mock.document.createElement("div") var parent + m.render(root, m("div", m("a", { - config: function(el) {parent = el.parentNode.parentNode} - }))); + config: function (el) { parent = el.parentNode.parentNode } + }))) + return parent === root }) - test(function() { + + test(function () { var root = mock.document.createElement("div") var count = 0 + m.render(root, m("div", m("a", { - config: function() { + config: function () { var island = mock.document.createElement("div") count++ if (count > 2) throw new Error("too much recursion...") m.render(island, m("div")) } - }))); + }))) + return count === 1 }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/129 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/129 var root = mock.document.createElement("div") - m.render(root, m("div", [["foo", "bar"], ["foo", "bar"], ["foo", "bar"]])); - m.render(root, m("div", ["asdf", "asdf2", "asdf3"])); + + m.render(root, m("div", [ + ["foo", "bar"], ["foo", "bar"], ["foo", "bar"] + ])) + + m.render(root, m("div", ["asdf", "asdf2", "asdf3"])) return true }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/98 - //insert at beginning + + test(function () { + // https://github.com/lhorie/mithril.js/issues/98 + // insert at beginning var root = mock.document.createElement("div") - m.render(root, [m("a", {key: 1}, 1), m("a", {key: 2}, 2), m("a", {key: 3}, 3)]) + + m.render(root, [ + m("a", {key: 1}, 1), + m("a", {key: 2}, 2), + m("a", {key: 3}, 3) + ]) + var firstBefore = root.childNodes[0] - m.render(root, [m("a", {key: 4}, 4), m("a", {key: 1}, 1), m("a", {key: 2}, 2), m("a", {key: 3}, 3)]) + + m.render(root, [ + m("a", {key: 4}, 4), + m("a", {key: 1}, 1), + m("a", {key: 2}, 2), + m("a", {key: 3}, 3) + ]) + var firstAfter = root.childNodes[1] - return firstBefore === firstAfter && root.childNodes[0].childNodes[0].nodeValue === "4" && root.childNodes.length === 4 + + return firstBefore === firstAfter && + root.childNodes[0].childNodes[0].nodeValue === "4" && + root.childNodes.length === 4 }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/98 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/98 var root = mock.document.createElement("div") - m.render(root, [m("a", {key: 1}, 1), m("a", {key: 2}, 2), m("a", {key: 3}, 3)]) + + m.render(root, [ + m("a", {key: 1}, 1), + m("a", {key: 2}, 2), + m("a", {key: 3}, 3) + ]) + var firstBefore = root.childNodes[0] - m.render(root, [m("a", {key: 4}, 4), m("a", {key: 1}, 1), m("a", {key: 2}, 2)]) + + m.render(root, [ + m("a", {key: 4}, 4), + m("a", {key: 1}, 1), + m("a", {key: 2}, 2) + ]) + var firstAfter = root.childNodes[1] - return firstBefore === firstAfter && root.childNodes[0].childNodes[0].nodeValue === "4" && root.childNodes.length === 3 + + return firstBefore === firstAfter && + root.childNodes[0].childNodes[0].nodeValue === "4" && + root.childNodes.length === 3 }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/98 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/98 var root = mock.document.createElement("div") - m.render(root, [m("a", {key: 1}, 1), m("a", {key: 2}, 2), m("a", {key: 3}, 3)]) + + m.render(root, [ + m("a", {key: 1}, 1), + m("a", {key: 2}, 2), + m("a", {key: 3}, 3) + ]) + var firstBefore = root.childNodes[1] - m.render(root, [m("a", {key: 2}, 2), m("a", {key: 3}, 3), m("a", {key: 4}, 4)]) + + m.render(root, [ + m("a", {key: 2}, 2), + m("a", {key: 3}, 3), + m("a", {key: 4}, 4) + ]) + var firstAfter = root.childNodes[0] - return firstBefore === firstAfter && root.childNodes[0].childNodes[0].nodeValue === "2" && root.childNodes.length === 3 + + return firstBefore === firstAfter && + root.childNodes[0].childNodes[0].nodeValue === "2" && + root.childNodes.length === 3 }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/98 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/98 var root = mock.document.createElement("div") - m.render(root, [m("a", {key: 1}, 1), m("a", {key: 2}, 2), m("a", {key: 3}, 3), m("a", {key: 4}, 4), m("a", {key: 5}, 5)]) + + m.render(root, [ + m("a", {key: 1}, 1), + m("a", {key: 2}, 2), + m("a", {key: 3}, 3), + m("a", {key: 4}, 4), + m("a", {key: 5}, 5) + ]) + var firstBefore = root.childNodes[0] var secondBefore = root.childNodes[1] var fourthBefore = root.childNodes[3] - m.render(root, [m("a", {key: 4}, 4), m("a", {key: 10}, 10), m("a", {key: 1}, 1), m("a", {key: 2}, 2)]) + + m.render(root, [ + m("a", {key: 4}, 4), + m("a", {key: 10}, 10), + m("a", {key: 1}, 1), + m("a", {key: 2}, 2) + ]) + var firstAfter = root.childNodes[2] var secondAfter = root.childNodes[3] var fourthAfter = root.childNodes[0] - return firstBefore === firstAfter && secondBefore === secondAfter && fourthBefore === fourthAfter && root.childNodes[1].childNodes[0].nodeValue === "10" && root.childNodes.length === 4 + + return firstBefore === firstAfter && + secondBefore === secondAfter && + fourthBefore === fourthAfter && + root.childNodes[1].childNodes[0].nodeValue === "10" && + root.childNodes.length === 4 }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/98 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/98 var root = mock.document.createElement("div") - m.render(root, [m("a", {key: 1}, 1), m("a", {key: 2}, 2), m("a", {key: 3}, 3), m("a", {key: 4}, 4), m("a", {key: 5}, 5)]) + + m.render(root, [ + m("a", {key: 1}, 1), + m("a", {key: 2}, 2), + m("a", {key: 3}, 3), + m("a", {key: 4}, 4), + m("a", {key: 5}, 5) + ]) + var firstBefore = root.childNodes[0] var secondBefore = root.childNodes[1] var fourthBefore = root.childNodes[3] - m.render(root, [m("a", {key: 4}, 4), m("a", {key: 10}, 10), m("a", {key: 2}, 2), m("a", {key: 1}, 1), m("a", {key: 6}, 6), m("a", {key: 7}, 7)]) + + m.render(root, [ + m("a", {key: 4}, 4), + m("a", {key: 10}, 10), + m("a", {key: 2}, 2), + m("a", {key: 1}, 1), + m("a", {key: 6}, 6), + m("a", {key: 7}, 7) + ]) + var firstAfter = root.childNodes[3] var secondAfter = root.childNodes[2] var fourthAfter = root.childNodes[0] - return firstBefore === firstAfter && secondBefore === secondAfter && fourthBefore === fourthAfter && root.childNodes[1].childNodes[0].nodeValue === "10" && root.childNodes[4].childNodes[0].nodeValue === "6" && root.childNodes[5].childNodes[0].nodeValue === "7" && root.childNodes.length === 6 + + return firstBefore === firstAfter && + secondBefore === secondAfter && + fourthBefore === fourthAfter && + root.childNodes[1].childNodes[0].nodeValue === "10" && + root.childNodes[4].childNodes[0].nodeValue === "6" && + root.childNodes[5].childNodes[0].nodeValue === "7" && + root.childNodes.length === 6 }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/149 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/149 var root = mock.document.createElement("div") - m.render(root, [m("a", {key: 1}), m("a", {key: 2}), m("a"), m("a", {key: 4}), m("a", {key: 5})]) + + m.render(root, [ + m("a", {key: 1}), + m("a", {key: 2}), + m("a"), + m("a", {key: 4}), + m("a", {key: 5}) + ]) + var firstBefore = root.childNodes[0] var secondBefore = root.childNodes[1] var thirdBefore = root.childNodes[2] var fourthBefore = root.childNodes[3] var fifthBefore = root.childNodes[4] - m.render(root, [m("a", {key: 4}), m("a", {key: 5}), m("a"), m("a", {key: 1}), m("a", {key: 2})]) + + m.render(root, [ + m("a", {key: 4}), + m("a", {key: 5}), + m("a"), + m("a", {key: 1}), + m("a", {key: 2}) + ]) + var firstAfter = root.childNodes[3] var secondAfter = root.childNodes[4] var thirdAfter = root.childNodes[2] var fourthAfter = root.childNodes[0] var fifthAfter = root.childNodes[1] - return firstBefore === firstAfter && secondBefore === secondAfter && thirdBefore === thirdAfter && fourthBefore === fourthAfter && fifthBefore === fifthAfter + + return firstBefore === firstAfter && + secondBefore === secondAfter && + thirdBefore === thirdAfter && + fourthBefore === fourthAfter && + fifthBefore === fifthAfter }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/246 - //insert at beginning with non-keyed in the middle + + test(function () { + // https://github.com/lhorie/mithril.js/issues/246 + // insert at beginning with non-keyed in the middle var root = mock.document.createElement("div") + m.render(root, [m("a", {key: 1}, 1)]) + var firstBefore = root.childNodes[0] - m.render(root, [m("a", {key: 2}, 2), m("br"), m("a", {key: 1}, 1)]) + + m.render(root, [ + m("a", {key: 2}, 2), + m("br"), + m("a", {key: 1}, 1) + ]) + var firstAfter = root.childNodes[2] - return firstBefore === firstAfter && root.childNodes[0].childNodes[0].nodeValue === "2" && root.childNodes.length === 3 + + return firstBefore === firstAfter && + root.childNodes[0].childNodes[0].nodeValue === "2" && + root.childNodes.length === 3 }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/134 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/134 var root = mock.document.createElement("div") m.render(root, m("div", {contenteditable: true}, "test")) mock.document.activeElement = root.childNodes[0] @@ -1922,237 +2456,408 @@ function testMithril(mock) { m.render(root, m("div", {contenteditable: false}, "test2")) return root.childNodes[0].childNodes[0].nodeValue === "test2" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/136 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/136 var root = mock.document.createElement("div") m.render(root, m("textarea", ["test"])) m.render(root, m("textarea", ["test1"])) return root.childNodes[0].value === "test1" }) - test(function() { + + test(function () { var root = mock.document.createElement("div") var unloaded = 0 + m.render(root, [ m("div", { key: 1, - config: function(el, init, ctx) { - ctx.onunload = function() { + config: function (el, init, ctx) { + ctx.onunload = function () { unloaded++ } } }) ]) + m.render(root, [ m("div", {key: 2}), m("div", { key: 1, - config: function(el, init, ctx) { - ctx.onunload = function() { + config: function (el, init, ctx) { + ctx.onunload = function () { unloaded++ } } }) ]) + return unloaded === 0 }) - test(function() { + + test(function () { var root = mock.document.createElement("div") var unloadedParent = 0 var unloadedChild = 0 - var configParent = function(el, init, ctx) { - ctx.onunload = function() { + + function configParent(el, init, ctx) { + ctx.onunload = function () { unloadedParent++ } } - var configChild = function(el, init, ctx) { - ctx.onunload = function() { + + function configChild(el, init, ctx) { + ctx.onunload = function () { unloadedChild++ } } - m.render(root, m("div", {config: configParent}, m("a", {config: configChild}))) - m.render(root, m("main", {config: configParent}, m("a", {config: configChild}))) + + m.render(root, m("div", {config: configParent}, [ + m("a", {config: configChild}) + ])) + + m.render(root, m("main", {config: configParent}, [ + m("a", {config: configChild}) + ])) + return unloadedParent === 1 && unloadedChild === 0 }) - test(function() { + + test(function () { var root = mock.document.createElement("div") var unloadedParent = 0 var unloadedChild = 0 - var configParent = function(el, init, ctx) { - ctx.onunload = function() { + + function configParent(el, init, ctx) { + ctx.onunload = function () { unloadedParent++ } } - var configChild = function(el, init, ctx) { - ctx.onunload = function() { + + function configChild(el, init, ctx) { + ctx.onunload = function () { unloadedChild++ } } - m.render(root, m("div", {config: configParent}, m("a", {config: configChild}))) - m.render(root, m("main", {config: configParent}, m("b", {config: configChild}))) + + m.render(root, m("div", {config: configParent}, [ + m("a", {config: configChild}) + ])) + + m.render(root, m("main", {config: configParent}, [ + m("b", {config: configChild}) + ])) + return unloadedParent === 1 && unloadedChild === 1 }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/150 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/150 var root = mock.document.createElement("div") m.render(root, [m("a"), m("div")]) m.render(root, [[], m("div")]) - return root.childNodes.length === 1 && root.childNodes[0].nodeName === "DIV" + + return root.childNodes.length === 1 && + root.childNodes[0].nodeName === "DIV" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/156 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/156 var root = mock.document.createElement("div") m.render(root, m("div", [ - ["a", "b", "c", "d"].map(function() { + ["a", "b", "c", "d"].map(function () { return [m("div"), " "] }), m("span") ])) return root.childNodes[0].childNodes[8].nodeName === "SPAN" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/157 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/157 var root = mock.document.createElement("div") - m.render(root, m("ul", [m("li", {key: 0}, 0), m("li", {key: 2}, 2), m("li", {key: 4}, 4)])) - m.render(root, m("ul", [m("li", {key: 0}, 0), m("li", {key: 1}, 1), m("li", {key: 2}, 2), m("li", {key: 3}, 3), m("li", {key: 4}, 4), m("li", {key: 5}, 5)])) - return root.childNodes[0].childNodes.map(function(n) {return n.childNodes[0].nodeValue}).join("") === "012345" + + m.render(root, m("ul", [ + m("li", {key: 0}, 0), + m("li", {key: 2}, 2), + m("li", {key: 4}, 4) + ])) + + m.render(root, m("ul", [ + m("li", {key: 0}, 0), + m("li", {key: 1}, 1), + m("li", {key: 2}, 2), + m("li", {key: 3}, 3), + m("li", {key: 4}, 4), + m("li", {key: 5}, 5) + ])) + + return root.childNodes[0].childNodes.map(function (n) { + return n.childNodes[0].nodeValue + }).join("") === "012345" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/157 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/157 var root = mock.document.createElement("div") m.render(root, m("input", {value: "a"})) m.render(root, m("input", {value: "aa"})) return root.childNodes[0].childNodes.length === 0 }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/157 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/157 var root = mock.document.createElement("div") - m.render(root, m("br", {"class": "a"})) - m.render(root, m("br", {"class": "aa"})) + m.render(root, m("br", {class: "a"})) + m.render(root, m("br", {class: "aa"})) return root.childNodes[0].childNodes.length === 0 }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/194 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/194 var root = mock.document.createElement("div") - m.render(root, m("ul", [m("li", {key: 0}, 0), m("li", {key: 1}, 1), m("li", {key: 2}, 2), m("li", {key: 3}, 3), m("li", {key: 4}, 4), m("li", {key: 5}, 5)])) - m.render(root, m("ul", [m("li", {key: 0}, 0), m("li", {key: 1}, 1), m("li", {key: 2}, 2), m("li", {key: 4}, 4), m("li", {key: 5}, 5)])) - return root.childNodes[0].childNodes.map(function(n) {return n.childNodes[0].nodeValue}).join("") === "01245" + + m.render(root, m("ul", [ + m("li", {key: 0}, 0), + m("li", {key: 1}, 1), + m("li", {key: 2}, 2), + m("li", {key: 3}, 3), + m("li", {key: 4}, 4), + m("li", {key: 5}, 5) + ])) + + m.render(root, m("ul", [ + m("li", {key: 0}, 0), + m("li", {key: 1}, 1), + m("li", {key: 2}, 2), + m("li", {key: 4}, 4), + m("li", {key: 5}, 5) + ])) + + return root.childNodes[0].childNodes.map(function (n) { + return n.childNodes[0].nodeValue + }).join("") === "01245" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/194 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/194 var root = mock.document.createElement("div") - m.render(root, m("ul", [m("li", {key: 0}, 0), m("li", {key: 1}, 1), m("li", {key: 2}, 2), m("li", {key: 3}, 3), m("li", {key: 4}, 4), m("li", {key: 5}, 5)])) - m.render(root, m("ul", [m("li", {key: 1}, 1), m("li", {key: 2}, 2), m("li", {key: 3}, 3), m("li", {key: 4}, 4), m("li", {key: 5}, 5), m("li", {key: 6}, 6)])) - m.render(root, m("ul", [m("li", {key: 12}, 12), m("li", {key: 13}, 13), m("li", {key: 14}, 14), m("li", {key: 15}, 15), m("li", {key: 16}, 16), m("li", {key: 17}, 17)])) - return root.childNodes[0].childNodes.map(function(n) {return n.childNodes[0].nodeValue}).join(",") === "12,13,14,15,16,17" + + m.render(root, m("ul", [ + m("li", {key: 0}, 0), + m("li", {key: 1}, 1), + m("li", {key: 2}, 2), + m("li", {key: 3}, 3), + m("li", {key: 4}, 4), + m("li", {key: 5}, 5) + ])) + + m.render(root, m("ul", [ + m("li", {key: 1}, 1), + m("li", {key: 2}, 2), + m("li", {key: 3}, 3), + m("li", {key: 4}, 4), + m("li", {key: 5}, 5), + m("li", {key: 6}, 6) + ])) + + m.render(root, m("ul", [ + m("li", {key: 12}, 12), + m("li", {key: 13}, 13), + m("li", {key: 14}, 14), + m("li", {key: 15}, 15), + m("li", {key: 16}, 16), + m("li", {key: 17}, 17) + ])) + + return root.childNodes[0].childNodes.map(function (n) { + return n.childNodes[0].nodeValue + }).join(",") === "12,13,14,15,16,17" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/206 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/206 var root = mock.document.createElement("div") m.render(root, m("div", undefined)) m.render(root, m("div", [m("div")])) return root.childNodes[0].childNodes.length === 1 }) - test(function() { + + test(function () { // https://github.com/lhorie/mithril.js/issues/206 var root = mock.document.createElement("div") m.render(root, m("div", null)) m.render(root, m("div", [m("div")])) return root.childNodes[0].childNodes.length === 1 }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/200 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/200 var root = mock.document.createElement("div") var unloaded1 = false + function unloadable1(element, isInit, context) { - context.onunload = function() { + context.onunload = function () { unloaded1 = true } } - m.render(root, [ m("div", {config: unloadable1}) ]) - m.render(root, [ ]) + + m.render(root, [m("div", {config: unloadable1})]) + m.render(root, []) var unloaded2 = false + function unloadable2(element, isInit, context) { - context.onunload = function() { + context.onunload = function () { unloaded2 = true } } - m.render(root, [ m("div", {config: unloadable2}) ]) - m.render(root, [ ]) + + m.render(root, [m("div", {config: unloadable2})]) + m.render(root, []) return unloaded1 === true && unloaded2 === true }) - test(function() { + + test(function () { var root = mock.document.createElement("div") m.render(root, [m("div.blue")]) m.render(root, [m("div.green", [m("div")]), m("div.blue")]) return root.childNodes.length === 2 }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/277 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/277 var root = mock.document.createElement("div") function Field() { - this.tag = "div"; - this.attrs = {}; - this.children = "hello"; + this.tag = "div" + this.attrs = {} + this.children = "hello" } m.render(root, new Field()) return root.childNodes.length === 1 }) - test(function() { + + test(function () { var root = mock.document.createElement("div") m.render(root, {foo: 123}) return root.childNodes.length === 0 }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/299 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/299 var root = mock.document.createElement("div") - m.render(root, m("div", [m("div", {key: 1}, 1), m("div", {key: 2}, 2), m("div", {key: 3}, 3), m("div", {key: 4}, 4), m("div", {key: 5}, 5), null, null, null, null, null, null, null, null, null, null])) - m.render(root, m("div", [null, null, m("div", {key: 3}, 3), null, null, m("div", {key: 6}, 6), null, null, m("div", {key: 9}, 9), null, null, m("div", {key: 12}, 12), null, null, m("div", {key: 15}, 15)])) - m.render(root, m("div", [m("div", {key: 1}, 1), m("div", {key: 2}, 2), m("div", {key: 3}, 3), m("div", {key: 4}, 4), m("div", {key: 5}, 5), null, null, null, null, null, null, null, null, null, null])) - return root.childNodes[0].childNodes.map(function(c) {return c.childNodes ? c.childNodes[0].nodeValue : c.nodeValue}).slice(0, 5).join("") === "12345" + + m.render(root, m("div", [ + m("div", {key: 1}, 1), + m("div", {key: 2}, 2), + m("div", {key: 3}, 3), + m("div", {key: 4}, 4), + m("div", {key: 5}, 5), + null, null, null, null, null, null, null, null, null, null + ])) + + m.render(root, m("div", [ + null, null, + m("div", {key: 3}, 3), + null, null, + m("div", {key: 6}, 6), + null, null, + m("div", {key: 9}, 9), + null, null, + m("div", {key: 12}, 12), + null, null, + m("div", {key: 15}, 15) + ])) + + m.render(root, m("div", [ + m("div", {key: 1}, 1), + m("div", {key: 2}, 2), + m("div", {key: 3}, 3), + m("div", {key: 4}, 4), + m("div", {key: 5}, 5), + null, null, null, null, null, null, null, null, null, null + ])) + + return root.childNodes[0].childNodes.map(function (c) { + return c.childNodes ? c.childNodes[0].nodeValue : c.nodeValue + }).slice(0, 5).join("") === "12345" }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/377 + + test(function () { + // https://github.com/lhorie/mithril.js/issues/377 var root = mock.document.createElement("div") - m.render(root, m("div", [m("div", 1), m("div", 2), [m("div", {key: 3}, 3), m("div", {key: 4}, 4), m("div", {key:5}, 5)], [m("div", {key: 6}, 6)]])) - m.render(root, m("div", [m("div", 1), null, [m("div", {key: 3}, 3), m("div", {key: 4}, 4), m("div", {key:5}, 5)], [m("div", {key: 6}, 6)]])) - return root.childNodes[0].childNodes.map(function(c) {return c.childNodes ? c.childNodes[0].nodeValue : c.nodeValue}).join("") === "13456" + + m.render(root, m("div", [ + m("div", 1), + m("div", 2), [m("div", {key: 3}, 3), + m("div", {key: 4}, 4), + m("div", {key: 5}, 5)], + [m("div", {key: 6}, 6)] + ])) + + m.render(root, m("div", [ + m("div", 1), + null, + [m("div", {key: 3}, 3), + m("div", {key: 4}, 4), + m("div", {key: 5}, 5)], + [m("div", {key: 6}, 6)] + ])) + + return root.childNodes[0].childNodes.map(function (c) { + return c.childNodes ? c.childNodes[0].nodeValue : c.nodeValue + }).join("") === "13456" }) - test(function() { + + test(function () { + // don't throw rendering console.log in Firefox var root = mock.document.createElement("div") - m.render(root, m("div", [console.log()])) // don't throw in Firefox + /* eslint-disable no-console */ + m.render(root, m("div", [console.log()])) + /* eslint-enable no-console */ return true }) - test(function() { + + test(function () { var root = mock.document.createElement("div") + m.render(root, [ m("#div-1", {key: 1}), m("#div-2", {key: 2}), m("#div-3", {key: 3}) ]) + root.appendChild(root.childNodes[1]) + m.render(root, [ m("#div-1", {key: 1}), m("#div-3", {key: 3}), m("#div-2", {key: 2}) ]) - return root.childNodes.map(function(node) {return node.id}).join() === "div-1,div-3,div-2" + + return root.childNodes.map(function (node) { + return node.id + }).join() === "div-1,div-3,div-2" }) - test(function() { + + test(function () { var root = mock.document.createElement("div") - m.render(root, m("div", function() {})) + m.render(root, m("div", function () {})) return root.childNodes[0].childNodes.length === 0 }) - test(function() { + + test(function () { var root = mock.document.createElement("div") m.render(root, m("div", "foo", m("a"))) m.render(root, m("div", "test")) return root.childNodes[0].childNodes.length === 1 }) - test(function() { - //if an element is preceded by a conditional, it should not lose its identity + + test(function () { + // if an element is preceded by a conditional, it should not lose its + // identity var root = mock.document.createElement("div") m.render(root, m("div", [m("a"), m("input[autofocus]")])) var before = root.childNodes[0].childNodes[1] @@ -2160,200 +2865,328 @@ function testMithril(mock) { var after = root.childNodes[0].childNodes[1] return before === after }) - test(function() { - //unkeyed element should maintain identity if mixed w/ keyed elements and identity can be inferred + + test(function () { + // unkeyed element should maintain identity if mixed w/ keyed elements + // and identity can be inferred var root = mock.document.createElement("div") - m.render(root, m("div", [m("a", {key: 1}), m("a", {key: 2}), m("a", {key: 3}), m("i")])) + + m.render(root, m("div", [ + m("a", {key: 1}), + m("a", {key: 2}), + m("a", {key: 3}), + m("i") + ])) + var before = root.childNodes[0].childNodes[3] - m.render(root, m("div", [m("b", {key: 3}), m("b", {key: 4}), m("i"), m("b", {key: 1})])) + + m.render(root, m("div", [ + m("b", {key: 3}), + m("b", {key: 4}), + m("i"), + m("b", {key: 1}) + ])) + var after = root.childNodes[0].childNodes[2] + return before === after }) - test(function() { - //unkeyed element should maintain identity if mixed w/ keyed elements and text nodes and identity can be inferred + + test(function () { + // unkeyed element should maintain identity if mixed w/ keyed elements + // and text nodes and identity can be inferred var root = mock.document.createElement("div") - m.render(root, m("div", [m("a", {key: 1}), m("a", {key: 2}), "foo", m("a", {key: 3}), m("i")])) + + m.render(root, m("div", [ + m("a", {key: 1}), + m("a", {key: 2}), + "foo", + m("a", {key: 3}), + m("i") + ])) + var before = root.childNodes[0].childNodes[4] - m.render(root, m("div", [m("a", {key: 3}), m("a", {key: 4}), "bar", m("i"), m("a", {key: 1})])) + + m.render(root, m("div", [ + m("a", {key: 3}), + m("a", {key: 4}), + "bar", + m("i"), + m("a", {key: 1}) + ])) + var after = root.childNodes[0].childNodes[3] + return before === after }) - test(function() { + + test(function () { var root = mock.document.createElement("div") - m.render(root, m("div", [m("a", {key: 1}), m("a", {key: 2}), null, m("a", {key: 3}), m("i")])) + + m.render(root, m("div", [ + m("a", {key: 1}), + m("a", {key: 2}), + null, + m("a", {key: 3}), + m("i") + ])) + var before = root.childNodes[0].childNodes[4] - m.render(root, m("div", [m("a", {key: 3}), m("a", {key: 4}), null, m("i"), m("a", {key: 1})])) + + m.render(root, m("div", [ + m("a", {key: 3}), + m("a", {key: 4}), + null, + m("i"), + m("a", {key: 1}) + ])) + var after = root.childNodes[0].childNodes[3] + return before === after }) - test(function() { + + test(function () { var root = mock.document.createElement("div") - m.render(root, m("div", [m("a", {key: 1}), m("a", {key: 2}), undefined, m("a", {key: 3}), m("i")])) + + m.render(root, m("div", [ + m("a", {key: 1}), + m("a", {key: 2}), + undefined, + m("a", {key: 3}), + m("i") + ])) + var before = root.childNodes[0].childNodes[4] - m.render(root, m("div", [m("a", {key: 3}), m("a", {key: 4}), undefined, m("i"), m("a", {key: 1})])) + + m.render(root, m("div", [ + m("a", {key: 3}), + m("a", {key: 4}), + undefined, + m("i"), + m("a", {key: 1}) + ])) + var after = root.childNodes[0].childNodes[3] + return before === after }) - test(function() { + + test(function () { var root = mock.document.createElement("div") - m.render(root, m("div", [m("a", {key: 1}), m("a", {key: 2}), m.trust("a"), m("a", {key: 3}), m("i")])) + + m.render(root, m("div", [ + m("a", {key: 1}), + m("a", {key: 2}), + m.trust("a"), + m("a", {key: 3}), + m("i") + ])) + var before = root.childNodes[0].childNodes[4] - m.render(root, m("div", [m("a", {key: 3}), m("a", {key: 4}), m.trust("a"), m("i"), m("a", {key: 1})])) + + m.render(root, m("div", [ + m("a", {key: 3}), + m("a", {key: 4}), + m.trust("a"), + m("i"), + m("a", {key: 1}) + ])) + var after = root.childNodes[0].childNodes[3] + return before === after }) - test(function() { + + test(function () { var root = mock.document.createElement("div") - var vdom = m("div.a", {"class": undefined}) + var vdom = m("div.a", {class: undefined}) m.render(root, vdom) - return root.childNodes[0]["class"] === "a" + return root.childNodes[0].class === "a" }) - test(function() { + + test(function () { var root = mock.document.createElement("div") m.render(root, m(".a", [1])) m.render(root, m(".a", [])) return root.childNodes[0].childNodes.length === 0 }) - //end m.render + // end m.render - //m.redraw - test(function() { - mock.requestAnimationFrame.$resolve() //setup + // m.redraw + test(function () { + mock.requestAnimationFrame.$resolve() // setup var controller var root = mock.document.createElement("div") m.mount(root, { - controller: function() {controller = this}, - view: function(ctrl) {return ctrl.value} + controller: function () { + /* eslint-disable consistent-this, no-invalid-this */ + controller = this + /* eslint-enable consistent-this, no-invalid-this */ + }, + view: function (ctrl) { return ctrl.value } }) + mock.requestAnimationFrame.$resolve() + var valueBefore = root.childNodes[0].nodeValue controller.value = "foo" + m.redraw() + mock.requestAnimationFrame.$resolve() + return valueBefore === "" && root.childNodes[0].nodeValue === "foo" }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup var count = 0 var root = mock.document.createElement("div") m.mount(root, { - controller: function() {}, - view: function() { - count++ - } + controller: function () {}, + view: function () { count++ } }) - mock.requestAnimationFrame.$resolve() //teardown - m.redraw() //should run synchronously + mock.requestAnimationFrame.$resolve() // teardown + m.redraw() // should run synchronously - m.redraw() //rest should run asynchronously since they're spamming + m.redraw() // rest should run asynchronously since they're spamming m.redraw() m.redraw() - mock.requestAnimationFrame.$resolve() //teardown + mock.requestAnimationFrame.$resolve() // teardown return count === 3 }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup var count = 0 var root = mock.document.createElement("div") + m.mount(root, { - controller: function() {}, - view: function() { + controller: function () {}, + view: function () { count++ } }) - mock.requestAnimationFrame.$resolve() //teardown - m.redraw(true) //should run synchronously - m.redraw(true) //forced to run synchronously + mock.requestAnimationFrame.$resolve() // teardown + + m.redraw(true) // should run synchronously + + m.redraw(true) // forced to run synchronously m.redraw(true) m.redraw(true) - mock.requestAnimationFrame.$resolve() //teardown + + mock.requestAnimationFrame.$resolve() // teardown return count === 5 }) - //m.route - test(function() { - mock.requestAnimationFrame.$resolve() //setup + // m.route + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") m.route.mode = "search" + m.route(root, "/test1", { - "/test1": {controller: function() {}, view: function() {return "foo"}} + "/test1": { + controller: function () {}, + view: function () { return "foo" } + } }) + mock.requestAnimationFrame.$resolve() - var result = mock.location.search === "?/test1" && root.childNodes[0].nodeValue === "foo" + var result = mock.location.search === "?/test1" && + root.childNodes[0].nodeValue === "foo" - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.pathname = "/" var root = mock.document.createElement("div") m.route.mode = "pathname" m.route(root, "/test2", { "/test2": { - controller: function() {}, - view: function() { + controller: function () {}, + view: function () { return [ "foo", - m("a", { href: "/test2", config: m.route }, "Test2") + m("a", {href: "/test2", config: m.route}, "Test2") ] } } }) mock.requestAnimationFrame.$resolve() - var result = mock.location.pathname === "/test2" && root.childNodes[0].nodeValue === "foo" && root.childNodes[1].href === "/test2" + var result = mock.location.pathname === "/test2" && + root.childNodes[0].nodeValue === "foo" && + root.childNodes[1].href === "/test2" - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.hash = "#" var root = mock.document.createElement("div") m.route.mode = "hash" m.route(root, "/test3", { - "/test3": {controller: function() {}, view: function() {return "foo"}} + "/test3": { + controller: function () {}, + view: function () { return "foo" } + } }) mock.requestAnimationFrame.$resolve() - var result = mock.location.hash === "#/test3" && root.childNodes[0].nodeValue === "foo" + var result = mock.location.hash === "#/test3" && + root.childNodes[0].nodeValue === "foo" - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") m.route.mode = "search" m.route(root, "/test4/foo", { - "/test4/:test": {controller: function() {}, view: function() {return m.route.param("test")}} + "/test4/:test": { + controller: function () {}, + view: function () { return m.route.param("test") } + } }) mock.requestAnimationFrame.$resolve() - var result = mock.location.search === "?/test4/foo" && root.childNodes[0].nodeValue === "foo" + var result = mock.location.search === "?/test4/foo" && + root.childNodes[0].nodeValue === "foo" - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" - var component = {controller: function() {}, view: function() {return m.route.param("test")}} + var component = { + controller: function () {}, + view: function () { return m.route.param("test") } + } var root = mock.document.createElement("div") m.route.mode = "search" @@ -2367,17 +3200,23 @@ function testMithril(mock) { var paramValueAfter = m.route.param("test") mock.requestAnimationFrame.$resolve() - var result = mock.location.search === "?/" && paramValueBefore === "foo" && paramValueAfter === undefined + var result = mock.location.search === "?/" && + paramValueBefore === "foo" && + paramValueAfter === undefined - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" - var component = {controller: function() {}, view: function() {return m.route.param("a1")}} + var component = { + controller: function () {}, + view: function () { return m.route.param("a1") } + } var root = mock.document.createElement("div") m.route.mode = "search" @@ -2391,18 +3230,24 @@ function testMithril(mock) { var paramValueAfter = m.route.param("a1") mock.requestAnimationFrame.$resolve() - var result = mock.location.search === "?/" && paramValueBefore === "foo" && paramValueAfter === undefined + var result = mock.location.search === "?/" && + paramValueBefore === "foo" && + paramValueAfter === undefined - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/61 - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + // https://github.com/lhorie/mithril.js/issues/61 + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" - var component = {controller: function() {}, view: function() {return m.route.param("a1")}} + var component = { + controller: function () {}, + view: function () { return m.route.param("a1") } + } var root = mock.document.createElement("div") m.route.mode = "search" @@ -2416,66 +3261,72 @@ function testMithril(mock) { var routeValueAfter = m.route() mock.requestAnimationFrame.$resolve() - var result = routeValueBefore === "/test7/foo" && routeValueAfter === "/" + var result = routeValueBefore === "/test7/foo" && + routeValueAfter === "/" - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") m.route.mode = "search" m.route(root, "/test8/foo/SEP/bar/baz", { "/test8/:test/SEP/:path...": { - controller: function() {}, - view: function() { + controller: function () {}, + view: function () { return m.route.param("test") + "_" + m.route.param("path") } } }) mock.requestAnimationFrame.$resolve() - var result = mock.location.search === "?/test8/foo/SEP/bar/baz" && root.childNodes[0].nodeValue === "foo_bar/baz" + var result = mock.location.search === "?/test8/foo/SEP/bar/baz" && + root.childNodes[0].nodeValue === "foo_bar/baz" - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") m.route.mode = "search" m.route(root, "/test9/foo/bar/SEP/baz", { "/test9/:test.../SEP/:path": { - controller: function() {}, - view: function() { + controller: function () {}, + view: function () { return m.route.param("test") + "_" + m.route.param("path") } } }) mock.requestAnimationFrame.$resolve() - var result = mock.location.search === "?/test9/foo/bar/SEP/baz" && root.childNodes[0].nodeValue === "foo/bar_baz" + var result = mock.location.search === "?/test9/foo/bar/SEP/baz" && + root.childNodes[0].nodeValue === "foo/bar_baz" - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") m.route.mode = "search" m.route(root, "/test10/foo%20bar", { "/test10/:test": { - controller: function() {}, - view: function() { + controller: function () {}, + view: function () { return m.route.param("test") } } @@ -2484,141 +3335,181 @@ function testMithril(mock) { var result = root.childNodes[0].nodeValue === "foo bar" - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") m.route.mode = "search" m.route(root, "/", { - "/": {controller: function() {}, view: function() {return "foo"}}, - "/test11": {controller: function() {}, view: function() {return "bar"}} + "/": { + controller: function () {}, + view: function () { return "foo" } + }, + "/test11": { + controller: function () {}, + view: function () { return "bar" } + } }) mock.requestAnimationFrame.$resolve() m.route("/test11/") mock.requestAnimationFrame.$resolve() - var result = mock.location.search === "?/test11/" && root.childNodes[0].nodeValue === "bar" + var result = mock.location.search === "?/test11/" && + root.childNodes[0].nodeValue === "bar" - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") m.route.mode = "search" m.route(root, "/", { - "/": {controller: function() {}, view: function() {}}, - "/test12": {controller: function() {}, view: function() {}} + "/": {controller: function () {}, view: function () {}}, + "/test12": {controller: function () {}, view: function () {}} }) mock.requestAnimationFrame.$resolve() m.route("/test12?a=foo&b=bar") mock.requestAnimationFrame.$resolve() - var result = mock.location.search === "?/test12?a=foo&b=bar" && m.route.param("a") === "foo" && m.route.param("b") === "bar" + var result = mock.location.search === "?/test12?a=foo&b=bar" && + m.route.param("a") === "foo" && + m.route.param("b") === "bar" - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") m.route.mode = "search" m.route(root, "/", { - "/": {controller: function() {}, view: function() {return "bar"}}, - "/test13/:test": {controller: function() {}, view: function() {return m.route.param("test")}} + "/": { + controller: function () {}, + view: function () { return "bar" } + }, + "/test13/:test": { + controller: function () {}, + view: function () { return m.route.param("test") } + } }) mock.requestAnimationFrame.$resolve() m.route("/test13/foo?test=bar") mock.requestAnimationFrame.$resolve() - var result = mock.location.search === "?/test13/foo?test=bar" && root.childNodes[0].nodeValue === "foo" + var result = mock.location.search === "?/test13/foo?test=bar" && + root.childNodes[0].nodeValue === "foo" - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") m.route.mode = "search" m.route(root, "/", { - "/": {controller: function() {}, view: function() {return "bar"}}, - "/test14": {controller: function() {}, view: function() {return "foo"}} + "/": { + controller: function () {}, + view: function () { return "bar" } + }, + "/test14": { + controller: function () {}, + view: function () { return "foo" } + } }) mock.requestAnimationFrame.$resolve() m.route("/test14?test&test2=") mock.requestAnimationFrame.$resolve() - var result = mock.location.search === "?/test14?test&test2=" && m.route.param("test") == null && m.route.param("test2") === "" + var result = mock.location.search === "?/test14?test&test2=" && + m.route.param("test") == null && + m.route.param("test2") === "" - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") m.route.mode = "search" m.route(root, "/", { - "/": {controller: function() {}, view: function() {}}, - "/test12": {controller: function() {}, view: function() {}} + "/": {controller: function () {}, view: function () {}}, + "/test12": {controller: function () {}, view: function () {}} }) mock.requestAnimationFrame.$resolve() m.route("/test12", {a: "foo", b: "bar"}) mock.requestAnimationFrame.$resolve() - var result = mock.location.search === "?/test12?a=foo&b=bar" && m.route.param("a") === "foo" && m.route.param("b") === "bar" + var result = mock.location.search === "?/test12?a=foo&b=bar" && + m.route.param("a") === "foo" && + m.route.param("b") === "bar" - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { // test route params returning params object if no key is given - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + // test route params returning params object if no key is given + mock.requestAnimationFrame.$resolve() // setup var root = mock.document.createElement("div") m.route.mode = "search" m.route(root, "/", { - "/": {controller: function() {}, view: function() {}}, - "/test12": {controller: function() {}, view: function() {}} + "/": {controller: function () {}, view: function () {}}, + "/test12": {controller: function () {}, view: function () {}} }) mock.requestAnimationFrame.$resolve() m.route("/test12", {a: "foo", b: "bar"}) mock.requestAnimationFrame.$resolve() - var params = m.route.param(); + var params = m.route.param() var result = params.a === "foo" && params.b === "bar" - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") var route1, route2 m.route.mode = "search" m.route(root, "/", { - "/": {controller: function() {route1 = m.route()}, view: function() {}}, - "/test13": {controller: function() {route2 = m.route()}, view: function() {}} + "/": { + controller: function () { route1 = m.route() }, + view: function () {} + }, + "/test13": { + controller: function () { route2 = m.route() }, + view: function () {} + } }) mock.requestAnimationFrame.$resolve() m.route("/test13") @@ -2626,12 +3517,13 @@ function testMithril(mock) { var result = route1 === "/" && route2 === "/test13" - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") @@ -2639,18 +3531,18 @@ function testMithril(mock) { m.route.mode = "search" m.route(root, "/", { "/": { - controller: function() {}, - view: function() { + controller: function () {}, + view: function () { return m("div", { - config: function(el, init, ctx) { - ctx.onunload = function() { + config: function (el, init, ctx) { + ctx.onunload = function () { unloaded++ } } }) } }, - "/test14": {controller: function() {}, view: function() {}} + "/test14": {controller: function () {}, view: function () {}} }) mock.requestAnimationFrame.$resolve() m.route("/test14") @@ -2658,12 +3550,13 @@ function testMithril(mock) { var result = unloaded === 1 - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") @@ -2671,13 +3564,13 @@ function testMithril(mock) { m.route.mode = "search" m.route(root, "/", { "/": { - controller: function() {}, - view: function() { + controller: function () {}, + view: function () { return [ m("div"), m("div", { - config: function(el, init, ctx) { - ctx.onunload = function() { + config: function (el, init, ctx) { + ctx.onunload = function () { unloaded++ } } @@ -2686,8 +3579,8 @@ function testMithril(mock) { } }, "/test15": { - controller: function() {}, - view: function() { + controller: function () {}, + view: function () { return [m("div")] } } @@ -2698,12 +3591,13 @@ function testMithril(mock) { var result = unloaded === 1 - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") @@ -2711,11 +3605,11 @@ function testMithril(mock) { m.route.mode = "search" m.route(root, "/", { "/": { - controller: function() {}, - view: function() { + controller: function () {}, + view: function () { return m("div", { - config: function(el, init, ctx) { - ctx.onunload = function() { + config: function (el, init, ctx) { + ctx.onunload = function () { unloaded++ } } @@ -2723,8 +3617,8 @@ function testMithril(mock) { } }, "/test16": { - controller: function() {}, - view: function() { + controller: function () {}, + view: function () { return m("a") } } @@ -2735,12 +3629,13 @@ function testMithril(mock) { var result = unloaded === 1 - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") @@ -2748,12 +3643,12 @@ function testMithril(mock) { m.route.mode = "search" m.route(root, "/", { "/": { - controller: function() {}, - view: function() { + controller: function () {}, + view: function () { return [ m("div", { - config: function(el, init, ctx) { - ctx.onunload = function() { + config: function (el, init, ctx) { + ctx.onunload = function () { unloaded++ } } @@ -2762,8 +3657,8 @@ function testMithril(mock) { } }, "/test17": { - controller: function() {}, - view: function() { + controller: function () {}, + view: function () { return m("a") } } @@ -2774,12 +3669,13 @@ function testMithril(mock) { var result = unloaded === 1 - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") @@ -2787,11 +3683,11 @@ function testMithril(mock) { m.route.mode = "search" m.route(root, "/", { "/": { - controller: function() {}, - view: function() { + controller: function () {}, + view: function () { return m("div", { - config: function(el, init, ctx) { - ctx.onunload = function() { + config: function (el, init, ctx) { + ctx.onunload = function () { unloaded++ } } @@ -2799,8 +3695,8 @@ function testMithril(mock) { } }, "/test18": { - controller: function() {}, - view: function() { + controller: function () {}, + view: function () { return [m("a")] } } @@ -2811,12 +3707,13 @@ function testMithril(mock) { var result = unloaded === 1 - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") @@ -2824,13 +3721,13 @@ function testMithril(mock) { m.route.mode = "search" m.route(root, "/", { "/": { - controller: function() {}, - view: function() { + controller: function () {}, + view: function () { return [ m("div", { key: 1, - config: function(el, init, ctx) { - ctx.onunload = function() { + config: function (el, init, ctx) { + ctx.onunload = function () { unloaded++ } } @@ -2839,13 +3736,13 @@ function testMithril(mock) { } }, "/test20": { - controller: function() {}, - view: function() { + controller: function () {}, + view: function () { return [ m("div", { key: 2, - config: function(el, init, ctx) { - ctx.onunload = function() { + config: function (el, init, ctx) { + ctx.onunload = function () { unloaded++ } } @@ -2860,12 +3757,13 @@ function testMithril(mock) { var result = unloaded === 1 - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") @@ -2873,13 +3771,13 @@ function testMithril(mock) { m.route.mode = "search" m.route(root, "/", { "/": { - controller: function() {}, - view: function() { + controller: function () {}, + view: function () { return [ m("div", { key: 1, - config: function(el, init, ctx) { - ctx.onunload = function() { + config: function (el, init, ctx) { + ctx.onunload = function () { unloaded++ } } @@ -2888,12 +3786,12 @@ function testMithril(mock) { } }, "/test21": { - controller: function() {}, - view: function() { + controller: function () {}, + view: function () { return [ m("div", { - config: function(el, init, ctx) { - ctx.onunload = function() { + config: function (el, init, ctx) { + ctx.onunload = function () { unloaded++ } } @@ -2908,65 +3806,67 @@ function testMithril(mock) { var result = unloaded === 1 - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") m.route.mode = "search" m.route(root, "/foo", { "/foo": { - controller: function() {}, - view: function() { - return m("div", "foo"); + controller: function () {}, + view: function () { + return m("div", "foo") } }, "/bar": { - controller: function() {}, - view: function() { - return m("div", "bar"); + controller: function () {}, + view: function () { + return m("div", "bar") } } }) mock.requestAnimationFrame.$resolve() - var foo = root.childNodes[0].childNodes[0].nodeValue; + var foo = root.childNodes[0].childNodes[0].nodeValue m.route("/bar") mock.requestAnimationFrame.$resolve() - var bar = root.childNodes[0].childNodes[0].nodeValue; + var bar = root.childNodes[0].childNodes[0].nodeValue var result = (foo === "foo" && bar === "bar") - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") var unloaded = 0 - var config = function(el, init, ctx) { - ctx.onunload = function() { + function config(el, init, ctx) { + ctx.onunload = function () { unloaded++ } } m.route.mode = "search" m.route(root, "/foo1", { "/foo1": { - controller: function() {}, - view: function() { - return m("div", m("a", {config: config}, "foo")); + controller: function () {}, + view: function () { + return m("div", m("a", {config: config}, "foo")) } }, "/bar1": { - controller: function() {}, - view: function() { - return m("main", m("a", {config: config}, "foo")); + controller: function () {}, + view: function () { + return m("main", m("a", {config: config}, "foo")) } } }) @@ -2976,12 +3876,13 @@ function testMithril(mock) { var result = unloaded === 1 - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") @@ -2989,12 +3890,12 @@ function testMithril(mock) { m.route.mode = "search" m.route(root, "/foo1", { "/foo1": { - controller: function() { + controller: function () { strategy = m.redraw.strategy() m.redraw.strategy("none") }, - view: function() { - return m("div"); + view: function () { + return m("div") } } }) @@ -3002,32 +3903,34 @@ function testMithril(mock) { var result = strategy === "all" && root.childNodes.length === 0 - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") - var strategy, count = 0 - var config = function(el, init) {if (!init) count++} + var count = 0 + var strategy + function config(el, init) { if (!init) count++ } m.route.mode = "search" m.route(root, "/foo1", { "/foo1": { - controller: function() {}, - view: function() { - return m("div", {config: config}); + controller: function () {}, + view: function () { + return m("div", {config: config}) } }, "/bar1": { - controller: function() { + controller: function () { strategy = m.redraw.strategy() m.redraw.strategy("redraw") }, - view: function() { - return m("div", {config: config}); + view: function () { + return m("div", {config: config}) } } }) @@ -3037,12 +3940,13 @@ function testMithril(mock) { var result = strategy === "all" && count === 1 - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") @@ -3050,40 +3954,45 @@ function testMithril(mock) { m.route.mode = "search" m.route(root, "/foo1", { "/foo1": { - controller: function() {this.number = 1}, - view: function(ctrl) { - return m("div", {onclick: function() { + controller: function () { this.number = 1 }, + view: function (ctrl) { + return m("div", {onclick: function () { strategy = m.redraw.strategy() ctrl.number++ m.redraw.strategy("none") - }}, ctrl.number); + }}, ctrl.number) } } }) root.childNodes[0].onclick({}) mock.requestAnimationFrame.$resolve() - var result = strategy === "diff" && root.childNodes[0].childNodes[0].nodeValue === "1" + var result = strategy === "diff" && + root.childNodes[0].childNodes[0].nodeValue === "1" - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") var count = 0 - var config = function(el, init ) {if (!init) count++} + function config(el, init) { if (!init) count++ } m.route.mode = "search" m.route(root, "/foo1", { "/foo1": { - controller: function() {}, - view: function() { - return m("div", {config: config, onclick: function() { - m.redraw.strategy("all") - }}); + controller: function () {}, + view: function () { + return m("div", { + config: config, + onclick: function () { + m.redraw.strategy("all") + } + }) } } }) @@ -3092,123 +4001,144 @@ function testMithril(mock) { var result = count === 2 - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") var value m.route(root, "/foo+bar", { "/:arg": { - controller: function() {value = m.route.param("arg")}, - view: function() { + controller: function () { value = m.route.param("arg") }, + view: function () { return "" } } }) var result = value === "foo+bar" - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") m.route.mode = "search" m.route(root, "/", { - "/": {controller: function() {}, view: function() {return "foo"}}, - "/test22": {controller: function() {}, view: function() {return "bar"}} + "/": { + controller: function () {}, + view: function () { return "foo" } + }, + "/test22": { + controller: function () {}, + view: function () { return "bar" } + } }) mock.requestAnimationFrame.$resolve() m.route(String("/test22/")) mock.requestAnimationFrame.$resolve() - var result = mock.location.search === "?/test22/" && root.childNodes[0].nodeValue === "bar" + var result = mock.location.search === "?/test22/" && + root.childNodes[0].nodeValue === "bar" - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") m.route.mode = "search" m.route(root, "/", { - "/": {controller: function() {}, view: function() {return "foo"}}, - "/test23": {controller: function() {}, view: function() {return "bar"}} + "/": { + controller: function () {}, + view: function () { return "foo" } + }, + "/test23": { + controller: function () {}, + view: function () { return "bar" } + } }) mock.requestAnimationFrame.$resolve() - m.route(new String("/test23/")) + m.route(new String("/test23/")) // eslint-disable-line no-new-wrappers mock.requestAnimationFrame.$resolve() - var result = mock.location.search === "?/test23/" && root.childNodes[0].nodeValue === "bar" + var result = mock.location.search === "?/test23/" && + root.childNodes[0].nodeValue === "bar" - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") var value m.route(root, String("/foo+bar"), { "/:arg": { - controller: function() {value = m.route.param("arg")}, - view: function() { - return "" - } + controller: function () { value = m.route.param("arg") }, + view: function () { return "" } } }) var result = value === "foo+bar" - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - mock.requestAnimationFrame.$resolve() //setup + + test(function () { + mock.requestAnimationFrame.$resolve() // setup mock.location.search = "?" var root = mock.document.createElement("div") + /* eslint-disable no-new-wrappers */ + var initial = new String("/foo+bar") + /* eslint-enable no-new-wrappers */ var value - m.route(root, new String("/foo+bar"), { + m.route(root, initial, { "/:arg": { - controller: function() {value = m.route.param("arg")}, - view: function() { + controller: function () { value = m.route.param("arg") }, + view: function () { return "" } } }) var result = value === "foo+bar" - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { + + test(function () { mock.requestAnimationFrame.$resolve() mock.location.search = "?" var root = mock.document.createElement("div") var a = {} - a.controller = function() {m.route("/b")} - a.view = function() {return "a"} + a.controller = function () { m.route("/b") } + a.view = function () { return "a" } var b = {} - b.controller = function() {} - b.view = function() {return "b"} + b.controller = function () {} + b.view = function () { return "b" } m.route(root, "/a", { "/a": a, @@ -3218,25 +4148,26 @@ function testMithril(mock) { var result = root.childNodes[0].nodeValue === "b" - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { + + test(function () { mock.requestAnimationFrame.$resolve() mock.location.search = "?" var root = mock.document.createElement("div") var a = {} - a.controller = function() { + a.controller = function () { m.route("/b?foo=1", {foo: 2}) } - a.view = function() {return "a"} + a.view = function () { return "a" } var b = {} - b.controller = function() {} - b.view = function() {return "b"} + b.controller = function () {} + b.view = function () { return "b" } m.route(root, "/", { "/": a, @@ -3246,12 +4177,12 @@ function testMithril(mock) { var result = mock.location.search === "?/b?foo=2" - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result - }) - test(function() { + + test(function () { mock.requestAnimationFrame.$resolve() mock.location.search = "?" mock.history.$$length = 0 @@ -3259,12 +4190,12 @@ function testMithril(mock) { var root = mock.document.createElement("div") var a = {} - a.controller = function() {} - a.view = function() {return "a"} + a.controller = function () {} + a.view = function () { return "a" } var b = {} - b.controller = function() {} - b.view = function() {return "b"} + b.controller = function () {} + b.view = function () { return "b" } m.route(root, "/a", { "/a": a, @@ -3278,12 +4209,12 @@ function testMithril(mock) { var result = mock.history.$$length === 1 - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result - }) - test(function() { + + test(function () { mock.requestAnimationFrame.$resolve() mock.location.search = "?" mock.history.$$length = 0 @@ -3291,12 +4222,12 @@ function testMithril(mock) { var root = mock.document.createElement("div") var a = {} - a.controller = function() {} - a.view = function() {return "a"} + a.controller = function () {} + a.view = function () { return "a" } var b = {} - b.controller = function() {} - b.view = function() {return "b"} + b.controller = function () {} + b.view = function () { return "b" } m.route(root, "/a", { "/a": a, @@ -3310,11 +4241,12 @@ function testMithril(mock) { var result = mock.history.$$length === 0 - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { + + test(function () { mock.requestAnimationFrame.$resolve() mock.location.search = "?" @@ -3322,15 +4254,15 @@ function testMithril(mock) { var initCount = 0 var a = {} - a.controller = function() {} - a.view = function() { - return m("a", {config: function(el, init) { + a.controller = function () {} + a.view = function () { + return m("a", {config: function (el, init) { if (!init) initCount++ }}) } var b = {} - b.controller = function() {} + b.controller = function () {} b.view = a.view m.route(root, "/a", { @@ -3345,11 +4277,12 @@ function testMithril(mock) { var result = initCount === 2 - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { + + test(function () { mock.requestAnimationFrame.$resolve() mock.location.search = "?" @@ -3357,16 +4290,16 @@ function testMithril(mock) { var initCount = 0 var a = {} - a.controller = function() {} - a.view = function() { - return m("a", {config: function(el, init, ctx) { + a.controller = function () {} + a.view = function () { + return m("a", {config: function (el, init, ctx) { ctx.retain = false if (!init) initCount++ }}) } var b = {} - b.controller = function() {} + b.controller = function () {} b.view = a.view m.route(root, "/a", { @@ -3381,11 +4314,12 @@ function testMithril(mock) { var result = initCount === 2 - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { + + test(function () { mock.requestAnimationFrame.$resolve() mock.location.search = "?" @@ -3393,16 +4327,16 @@ function testMithril(mock) { var initCount = 0 var a = {} - a.controller = function() {} - a.view = function() { - return m("a", {config: function(el, init, ctx) { + a.controller = function () {} + a.view = function () { + return m("a", {config: function (el, init, ctx) { ctx.retain = true if (!init) initCount++ }}) } var b = {} - b.controller = function() {} + b.controller = function () {} b.view = a.view m.route(root, "/a", { @@ -3417,11 +4351,12 @@ function testMithril(mock) { var result = initCount === 1 - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { + + test(function () { mock.requestAnimationFrame.$resolve() mock.location.search = "?" @@ -3429,15 +4364,15 @@ function testMithril(mock) { var initCount = 0 var a = {} - a.controller = function() {m.redraw.strategy("diff")} - a.view = function() { - return m("a", {config: function(el, init) { + a.controller = function () { m.redraw.strategy("diff") } + a.view = function () { + return m("a", {config: function (el, init) { if (!init) initCount++ }}) } var b = {} - b.controller = function() {m.redraw.strategy("diff")} + b.controller = function () { m.redraw.strategy("diff") } b.view = a.view m.route(root, "/a", { @@ -3452,11 +4387,12 @@ function testMithril(mock) { var result = initCount === 1 - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { + + test(function () { mock.requestAnimationFrame.$resolve() mock.location.search = "?" @@ -3464,16 +4400,16 @@ function testMithril(mock) { var initCount = 0 var a = {} - a.controller = function() {m.redraw.strategy("diff")} - a.view = function() { - return m("a", {config: function(el, init, ctx) { + a.controller = function () { m.redraw.strategy("diff") } + a.view = function () { + return m("a", {config: function (el, init, ctx) { ctx.retain = true if (!init) initCount++ }}) } var b = {} - b.controller = function() {m.redraw.strategy("diff")} + b.controller = function () { m.redraw.strategy("diff") } b.view = a.view m.route(root, "/a", { @@ -3488,11 +4424,12 @@ function testMithril(mock) { var result = initCount === 1 - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { + + test(function () { mock.requestAnimationFrame.$resolve() mock.location.search = "?" @@ -3500,16 +4437,16 @@ function testMithril(mock) { var initCount = 0 var a = {} - a.controller = function() {m.redraw.strategy("diff")} - a.view = function() { - return m("a", {config: function(el, init, ctx) { + a.controller = function () { m.redraw.strategy("diff") } + a.view = function () { + return m("a", {config: function (el, init, ctx) { ctx.retain = false if (!init) initCount++ }}) } var b = {} - b.controller = function() {m.redraw.strategy("diff")} + b.controller = function () { m.redraw.strategy("diff") } b.view = a.view m.route(root, "/a", { @@ -3524,11 +4461,12 @@ function testMithril(mock) { var result = initCount === 2 - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { + + test(function () { mock.requestAnimationFrame.$resolve() mock.location.search = "?" @@ -3536,18 +4474,18 @@ function testMithril(mock) { var initCount = 0 var a = {} - a.controller = function() {} - a.view = function() { - return m("div", m("a", {config: function(el, init, ctx) { + a.controller = function () {} + a.view = function () { + return m("div", m("a", {config: function (el, init, ctx) { ctx.retain = true if (!init) initCount++ }})) } var b = {} - b.controller = function() {} - b.view = function() { - return m("section", m("a", {config: function(el, init, ctx) { + b.controller = function () {} + b.view = function () { + return m("section", m("a", {config: function (el, init, ctx) { ctx.retain = true if (!init) initCount++ }})) @@ -3565,11 +4503,12 @@ function testMithril(mock) { var result = initCount === 1 - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { + + test(function () { mock.requestAnimationFrame.$resolve() mock.location.search = "?" @@ -3577,18 +4516,18 @@ function testMithril(mock) { var initCount = 0 var a = {} - a.controller = function() {} - a.view = function() { - return m("div", m("a", {config: function(el, init, ctx) { + a.controller = function () {} + a.view = function () { + return m("div", m("a", {config: function (el, init, ctx) { ctx.retain = false if (!init) initCount++ }})) } var b = {} - b.controller = function() {} - b.view = function() { - return m("section", m("a", {config: function(el, init, ctx) { + b.controller = function () {} + b.view = function () { + return m("section", m("a", {config: function (el, init, ctx) { ctx.retain = false if (!init) initCount++ }})) @@ -3606,11 +4545,12 @@ function testMithril(mock) { var result = initCount === 2 - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { + + test(function () { mock.requestAnimationFrame.$resolve() mock.location.search = "?" @@ -3618,17 +4558,17 @@ function testMithril(mock) { var initCount = 0 var a = {} - a.controller = function() {} - a.view = function() { - return m("div", m("a", {config: function(el, init) { + a.controller = function () {} + a.view = function () { + return m("div", m("a", {config: function (el, init) { if (!init) initCount++ }})) } var b = {} - b.controller = function() {} - b.view = function() { - return m("section", m("a", {config: function(el, init) { + b.controller = function () {} + b.view = function () { + return m("section", m("a", {config: function (el, init) { if (!init) initCount++ }})) } @@ -3645,11 +4585,12 @@ function testMithril(mock) { var result = initCount === 2 - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { + + test(function () { mock.requestAnimationFrame.$resolve() mock.location.search = "?" @@ -3657,18 +4598,18 @@ function testMithril(mock) { var initCount = 0 var a = {} - a.controller = function() {m.redraw.strategy("diff")} - a.view = function() { - return m("div", m("a", {config: function(el, init, ctx) { + a.controller = function () { m.redraw.strategy("diff") } + a.view = function () { + return m("div", m("a", {config: function (el, init, ctx) { ctx.retain = true if (!init) initCount++ }})) } var b = {} - b.controller = function() {m.redraw.strategy("diff")} - b.view = function() { - return m("section", m("a", {config: function(el, init, ctx) { + b.controller = function () { m.redraw.strategy("diff") } + b.view = function () { + return m("section", m("a", {config: function (el, init, ctx) { ctx.retain = true if (!init) initCount++ }})) @@ -3686,11 +4627,12 @@ function testMithril(mock) { var result = initCount === 1 - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { + + test(function () { mock.requestAnimationFrame.$resolve() mock.location.search = "?" @@ -3698,18 +4640,18 @@ function testMithril(mock) { var initCount = 0 var a = {} - a.controller = function() {m.redraw.strategy("diff")} - a.view = function() { - return m("div", m("a", {config: function(el, init, ctx) { + a.controller = function () { m.redraw.strategy("diff") } + a.view = function () { + return m("div", m("a", {config: function (el, init, ctx) { ctx.retain = false if (!init) initCount++ }})) } var b = {} - b.controller = function() {m.redraw.strategy("diff")} - b.view = function() { - return m("section", m("a", {config: function(el, init, ctx) { + b.controller = function () { m.redraw.strategy("diff") } + b.view = function () { + return m("section", m("a", {config: function (el, init, ctx) { ctx.retain = false if (!init) initCount++ }})) @@ -3727,11 +4669,12 @@ function testMithril(mock) { var result = initCount === 2 - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { + + test(function () { mock.requestAnimationFrame.$resolve() mock.location.search = "?" @@ -3739,17 +4682,17 @@ function testMithril(mock) { var initCount = 0 var a = {} - a.controller = function() {m.redraw.strategy("diff")} - a.view = function() { - return m("div", m("a", {config: function(el, init) { + a.controller = function () { m.redraw.strategy("diff") } + a.view = function () { + return m("div", m("a", {config: function (el, init) { if (!init) initCount++ }})) } var b = {} - b.controller = function() {m.redraw.strategy("diff")} - b.view = function() { - return m("section", m("a", {config: function(el, init) { + b.controller = function () { m.redraw.strategy("diff") } + b.view = function () { + return m("section", m("a", {config: function (el, init) { if (!init) initCount++ }})) } @@ -3766,12 +4709,13 @@ function testMithril(mock) { var result = initCount === 1 - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { - //retain flag should work inside component + + test(function () { + // retain flag should work inside component mock.requestAnimationFrame.$resolve() mock.location.search = "?" @@ -3779,26 +4723,26 @@ function testMithril(mock) { var initCount = 0 var a = {} - a.controller = function() {} - a.view = function() { - return m("div", m("a", {config: function(el, init, ctx) { + a.controller = function () {} + a.view = function () { + return m("div", m("a", {config: function (el, init, ctx) { ctx.retain = true if (!init) initCount++ }})) } var b = {} - b.controller = function() {m.redraw.strategy("diff")} - b.view = function() { - return m("section", m("a", {config: function(el, init, ctx) { + b.controller = function () { m.redraw.strategy("diff") } + b.view = function () { + return m("section", m("a", {config: function (el, init, ctx) { ctx.retain = true if (!init) initCount++ }})) } m.route(root, "/a", { - "/a": {view: function() {return m("div", a)}}, - "/b": {view: function() {return m("div", b)}} + "/a": {view: function () { return m("div", a) }}, + "/b": {view: function () { return m("div", b) }} }) mock.requestAnimationFrame.$resolve() @@ -3807,11 +4751,12 @@ function testMithril(mock) { mock.requestAnimationFrame.$resolve() var result = initCount === 1 - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result }) - test(function() { + + test(function () { // https://github.com/lhorie/mithril.js/pull/571 mock.requestAnimationFrame.$resolve() mock.location.search = "?" @@ -3819,16 +4764,16 @@ function testMithril(mock) { var root = mock.document.createElement("div") var a = {} - a.controller = function() {} - a.view = function() { - return m("div", {config: function(elm) { + a.controller = function () {} + a.view = function () { + return m("div", {config: function (elm) { elm.childNodes[0].modified = true }}, m("div")) } var b = {} - b.controller = function() {} - b.view = function() { + b.controller = function () {} + b.view = function () { return m("div", m("div")) } @@ -3841,29 +4786,43 @@ function testMithril(mock) { m.route("/b") mock.requestAnimationFrame.$resolve() - var result = !root.childNodes[0].childNodes[0].modified; + var result = !root.childNodes[0].childNodes[0].modified - m.mount(root, null) //teardown + m.mount(root, null) // teardown return result - }); - //end m.route + }) + // end m.route - //m.route.parseQueryString - test(function() { - var args = m.route.parseQueryString("foo=bar&hello%5B%5D=world&hello%5B%5D=mars&hello%5B%5D=pluto") - return args["hello[]"] instanceof Array && args["hello[]"].indexOf("world") > -1 && args["hello[]"].indexOf("mars") > -1 && args["hello[]"].indexOf("pluto") > -1 + // m.route.parseQueryString + test(function () { + var str = "foo=bar&hello%5B%5D=world&hello%5B%5D=mars&hello%5B%5D=pluto" + var args = m.route.parseQueryString(str) + + return args["hello[]"] instanceof Array && + args["hello[]"].indexOf("world") > -1 && + args["hello[]"].indexOf("mars") > -1 && + args["hello[]"].indexOf("pluto") > -1 }) - test(function() { - var args = m.route.parseQueryString("foo=bar&hello=world&hello=mars&bam=&yup") - return args.foo === "bar" && args.hello[0] === "world" && args.hello[1] === "mars" && args.bam === "" && args.yup == null + + test(function () { + var str = "foo=bar&hello=world&hello=mars&bam=&yup" + var args = m.route.parseQueryString(str) + + return args.foo === "bar" && + args.hello[0] === "world" && + args.hello[1] === "mars" && + args.bam === "" && + args.yup == null }) - test(function() { + + test(function () { var args = m.route.parseQueryString("") return Object.keys(args).length === 0 }) - //m.route.buildQueryString - test(function() { + + // m.route.buildQueryString + test(function () { var string = m.route.buildQueryString({ foo: "bar", hello: ["world", "mars", "mars"], @@ -3874,38 +4833,47 @@ function testMithril(mock) { yup: null, removed: undefined }) - return string === "foo=bar&hello=world&hello=mars&world%5Btest%5D=3&bam=&yup" + var expected = "foo=bar&hello=world&hello=mars&" + + "world%5Btest%5D=3&bam=&yup" + return string === expected }) - test(function() { - var string = m.route.buildQueryString({}); + + test(function () { + var string = m.route.buildQueryString({}) return string === "" }) - //m.prop - test(function() { + + // m.prop + test(function () { var prop = m.prop("test") return prop() === "test" }) - test(function() { + + test(function () { var prop = m.prop("test") prop("foo") return prop() === "foo" }) - test(function() { + + test(function () { var prop = m.prop("test") return JSON.stringify(prop) === '"test"' }) - test(function() { + + test(function () { var obj = {prop: m.prop("test")} return JSON.stringify(obj) === '{"prop":"test"}' }) - test(function() { + + test(function () { var defer = m.deferred() var prop = m.prop(defer.promise) defer.resolve("test") return prop() === "test" }) - test(function() { + + test(function () { var defer = m.deferred() var prop = m.prop(defer.promise).then(function () { return "test2" @@ -3914,113 +4882,183 @@ function testMithril(mock) { return prop() === "test2" }) - test(function() { + + test(function () { var prop = m.prop(null) return prop() === null }) - //m.request - test(function() { + // m.request + test(function () { var prop = m.request({method: "GET", url: "test"}) mock.XMLHttpRequest.$instances.pop().onreadystatechange() return prop().method === "GET" && prop().url === "test" }) - test(function() { - var prop = m.request({method: "GET", url: "test"}).then(function() {return "foo"}) + + test(function () { + var prop = m.request({method: "GET", url: "test"}) + .then(function () { return "foo" }) mock.XMLHttpRequest.$instances.pop().onreadystatechange() return prop() === "foo" }) - test(function() { - var prop = m.request({method: "POST", url: "http://domain.com:80", data: {}}).then(function(value) {return value}) + + test(function () { + var prop = m.request({ + method: "POST", url: "http://domain.com:80", + data: {} + }).then(function (value) { return value }) + mock.XMLHttpRequest.$instances.pop().onreadystatechange() + return prop().url === "http://domain.com:80" }) - test(function() { - var prop = m.request({method: "POST", url: "http://domain.com:80/:test1", data: {test1: "foo"}}).then(function(value) {return value}) + + test(function () { + var prop = m.request({ + method: "POST", + url: "http://domain.com:80/:test1", + data: {test1: "foo"} + }).then(function (value) { return value }) + mock.XMLHttpRequest.$instances.pop().onreadystatechange() return prop().url === "http://domain.com:80/foo" }) - test(function() { + + test(function () { var error = m.prop("no error") - var prop = m.request({method: "GET", url: "test", deserialize: function() {throw new Error("error occurred")}}).then(null, error) + + var prop = m.request({ + method: "GET", + url: "test", + deserialize: function () { throw new Error("error occurred") } + }).then(null, error) + mock.XMLHttpRequest.$instances.pop().onreadystatechange() - return prop().message === "error occurred" && error().message === "error occurred" + return prop().message === "error occurred" && + error().message === "error occurred" }) - test(function() { + + test(function () { var error = m.prop("no error") - var prop = m.request({method: "GET", url: "test", deserialize: function() {throw new Error("error occurred")}})["catch"](error) + + var prop = m.request({ + method: "GET", + url: "test", + deserialize: function () { throw new Error("error occurred") } + }).catch(error) + mock.XMLHttpRequest.$instances.pop().onreadystatechange() - return prop().message === "error occurred" && error().message === "error occurred" + return prop().message === "error occurred" && + error().message === "error occurred" }) - test(function() { - var error = m.prop("no error"), exception - var prop = m.request({method: "GET", url: "test", deserialize: function() {throw new TypeError("error occurred")}}).then(null, error) - try {mock.XMLHttpRequest.$instances.pop().onreadystatechange()} - catch (e) {exception = e} - return prop() === undefined && error() === "no error" && exception.message === "error occurred" - }) - test(function() { + + test(function () { var error = m.prop("no error") - m.request({method: "POST", url: "test", data: {foo: 1}}).then(null, error) + var exception + + var prop = m.request({ + method: "GET", + url: "test", + deserialize: function () { throw new TypeError("error occurred") } + }).then(null, error) + + try { + mock.XMLHttpRequest.$instances.pop().onreadystatechange() + } catch (e) { + exception = e + } + + return prop() === undefined && + error() === "no error" && + exception.message === "error occurred" + }) + + test(function () { + var error = m.prop("no error") + + m.request({method: "POST", url: "test", data: {foo: 1}}) + .then(null, error) + var xhr = mock.XMLHttpRequest.$instances.pop() xhr.onreadystatechange() - return xhr.$headers["Content-Type"] === "application/json; charset=utf-8" + + var expected = "application/json; charset=utf-8" + + return xhr.$headers["Content-Type"] === expected }) - test(function() { + + test(function () { var error = m.prop("no error") m.request({method: "POST", url: "test"}).then(null, error) var xhr = mock.XMLHttpRequest.$instances.pop() xhr.onreadystatechange() return xhr.$headers["Content-Type"] === undefined }) - test(function() { - var prop = m.request({method: "POST", url: "test", initialValue: "foo"}).then(function(data) { return data; }) - var initialValue = prop(); - mock.XMLHttpRequest.$instances.pop().onreadystatechange() - return initialValue === "foo" - }) - test(function() { + test(function () { var prop = m.request({method: "POST", url: "test", initialValue: "foo"}) - var initialValue = prop(); + .then(function (data) { return data }) + + var initialValue = prop() mock.XMLHttpRequest.$instances.pop().onreadystatechange() return initialValue === "foo" }) - test(function() { - var prop = m.request({method: "POST", url: "test", initialValue: "foo"}).then(function() {return "bar"}) + + test(function () { + var prop = m.request({method: "POST", url: "test", initialValue: "foo"}) + var initialValue = prop() + mock.XMLHttpRequest.$instances.pop().onreadystatechange() + + return initialValue === "foo" + }) + + test(function () { + var prop = m.request({method: "POST", url: "test", initialValue: "foo"}) + .then(function () { return "bar" }) mock.XMLHttpRequest.$instances.pop().onreadystatechange() return prop() === "bar" }) - test(function() { + + test(function () { var prop = m.request({method: "GET", url: "test", data: {foo: 1}}) mock.XMLHttpRequest.$instances.pop().onreadystatechange() return prop().url === "test?foo=1" }) - test(function() { + + test(function () { var prop = m.request({method: "POST", url: "test", data: {foo: 1}}) mock.XMLHttpRequest.$instances.pop().onreadystatechange() return prop().url === "test" }) - test(function() { + + test(function () { var prop = m.request({method: "GET", url: "test", data: {foo: [1, 2]}}) mock.XMLHttpRequest.$instances.pop().onreadystatechange() return prop().url === "test?foo=1&foo=2" }) - test(function() { + + test(function () { var value var prop1 = m.request({method: "GET", url: "test", initialValue: 123}) + var val1 = prop1() - var prop2 = prop1.then(function() {return 1}) + var prop2 = prop1.then(function () { return 1 }) var val2 = prop2() - var prop3 = prop1.then(function(v) {value = v}) + var prop3 = prop1.then(function (v) { value = v }) var val3 = prop3() + mock.XMLHttpRequest.$instances.pop().onreadystatechange() - return val1 === 123 && val2 === 123 && val3 === 123 && value.method === "GET" && value.url === "test" + + return val1 === 123 && + val2 === 123 && + val3 === 123 && + value.method === "GET" && + value.url === "test" }) // m.request over jsonp - test(function(){ + test(function (){ // script tags cannot be appended directly on the document var body = mock.document.createElement("body") mock.document.body = body @@ -4028,18 +5066,22 @@ function testMithril(mock) { var error = m.prop("no error") var data - m.request({url: "/test", dataType: "jsonp"}).then(function(received) {data = received}, error) - var callbackKey = Object.keys(mock).filter(function(globalKey){ + m.request({url: "/test", dataType: "jsonp"}) + .then(function (received) { data = received }, error) + var callbackKey = Object.keys(mock).filter(function (globalKey){ return globalKey.indexOf("mithril_callback") > -1 }).pop() - var scriptTag = [].slice.call(mock.document.getElementsByTagName("script")).filter(function(script){ + var scripts = mock.document.getElementsByTagName("script") + var scriptTag = [].slice.call(scripts).filter(function (script){ return script.src.indexOf(callbackKey) > -1 }).pop() mock[callbackKey]({foo: "bar"}) mock.document.removeChild(body) - return scriptTag.src.indexOf("/test?callback=mithril_callback") > -1 && data.foo === "bar" + return scriptTag.src.indexOf("/test?callback=mithril_callback") > -1 && + data.foo === "bar" }) - test(function(){ + + test(function (){ // script tags cannot be appended directly on the document var body = mock.document.createElement("body") mock.document.body = body @@ -4047,300 +5089,418 @@ function testMithril(mock) { var error = m.prop("no error") var data - m.request({url: "/test", dataType: "jsonp", callbackKey: "jsonpCallback"}).then(function(received) {data = received}, error) - var callbackKey = Object.keys(mock).filter(function(globalKey){ + m.request({ + url: "/test", + dataType: "jsonp", + callbackKey: "jsonpCallback" + }).then(function (received) { data = received }, error) + + var callbackKey = Object.keys(mock).filter(function (globalKey){ return globalKey.indexOf("mithril_callback") > -1 }).pop() - var scriptTag = [].slice.call(mock.document.getElementsByTagName("script")).filter(function(script){ + + var scripts = mock.document.getElementsByTagName("script") + var scriptTag = [].slice.call(scripts).filter(function (script){ return script.src.indexOf(callbackKey) > -1 - }).pop(); + }).pop() + mock[callbackKey]({foo: "bar1"}) mock.document.removeChild(body) - return scriptTag.src.indexOf("/test?jsonpCallback=mithril_callback") > -1 && data.foo === "bar1" + + var url = "/test?jsonpCallback=mithril_callback" + return scriptTag.src.indexOf(url) > -1 && + data.foo === "bar1" }) - test(function(){ + + test(function (){ var body = mock.document.createElement("body") mock.document.body = body mock.document.appendChild(body) var req = m.request({url: "/test", dataType: "jsonp"}) - var callbackKey = Object.keys(mock).filter(function(globalKey){ + var callbackKey = Object.keys(mock).filter(function (globalKey){ return globalKey.indexOf("mithril_callback") > -1 }).pop() - ;[].slice.call(mock.document.getElementsByTagName("script")).filter(function(script){ + var scripts = mock.document.getElementsByTagName("script") + ;[].slice.call(scripts).filter(function (script){ return script.src.indexOf(callbackKey) > -1 - }).pop(); + }).pop() mock[callbackKey]({foo: "bar1"}) var out = {foo: "bar1"} mock.document.removeChild(body) return JSON.stringify(out) === JSON.stringify(req()) }) - test(function(){ + + test(function (){ var body = mock.document.createElement("body") mock.document.body = body mock.document.appendChild(body) m.request({url: "/test", dataType: "jsonp", data: {foo: "bar"}}) - var callbackKey = Object.keys(mock).filter(function(globalKey){ + var callbackKey = Object.keys(mock).filter(function (globalKey){ return globalKey.indexOf("mithril_callback") > -1 }).pop() - var scriptTag = [].slice.call(mock.document.getElementsByTagName("script")).filter(function(script){ + var scripts = mock.document.getElementsByTagName("script") + var scriptTag = [].slice.call(scripts).filter(function (script){ return script.src.indexOf(callbackKey) > -1 - }).pop(); + }).pop() mock[callbackKey]({foo: "bar"}) return scriptTag.src.indexOf("foo=bar") > -1 }) - test(function(){ - var body = mock.document.createElement("body"); - mock.document.body = body; - mock.document.appendChild(body); - m.request({url: "/test", dataType: "jsonp", method: "GET", data: {foo: "bar"}}); - var callbackKey = Object.keys(mock).filter(function(globalKey){ + test(function (){ + var body = mock.document.createElement("body") + mock.document.body = body + mock.document.appendChild(body) + + m.request({ + url: "/test", + dataType: "jsonp", + method: "GET", + data: {foo: "bar"} + }) + var callbackKey = Object.keys(mock).filter(function (globalKey){ return globalKey.indexOf("mithril_callback") > -1 }).pop() - var scriptTag = [].slice.call(mock.document.getElementsByTagName("script")).filter(function(script){ + var scripts = mock.document.getElementsByTagName("script") + var scriptTag = [].slice.call(scripts).filter(function (script){ return script.src.indexOf(callbackKey) > -1 - }).pop(); + }).pop() mock[callbackKey]({foo: "bar"}) - mock.document.removeChild(body); - return scriptTag.src.match(/foo=bar/g).length === 1; + mock.document.removeChild(body) + return scriptTag.src.match(/foo=bar/g).length === 1 }) - //m.deferred - test(function() { - var value + // m.deferred + test(function () { var deferred = m.deferred() - deferred.promise.then(function(data) {value = data}) + var value + deferred.promise.then(function (data) { value = data }) deferred.resolve("test") return value === "test" }) - test(function() { - var value + + test(function () { var deferred = m.deferred() - deferred.promise.then(function() {return "foo"}).then(function(data) {value = data}) + var value + + deferred.promise + .then(function () { return "foo" }) + .then(function (data) { value = data }) + deferred.resolve("test") return value === "foo" }) - test(function() { - var value + + test(function () { var deferred = m.deferred() - deferred.promise.then(null, function(data) {value = data}) + var value + deferred.promise.then(null, function (data) { value = data }) deferred.reject("test") return value === "test" }) - test(function() { + + test(function () { var value var deferred = m.deferred() - deferred.promise["catch"](function(data) {value = data}) + deferred.promise.catch(function (data) { value = data }) deferred.reject("test") return value === "test" }) - test(function() { - var value + + test(function () { var deferred = m.deferred() - deferred.promise.then(null, function() {return "foo"}).then(function(data) {value = data}) + var value + + deferred.promise + .then(null, function () { return "foo" }) + .then(function (data) { value = data }) + deferred.reject("test") return value === "foo" }) - test(function() { - var value + + test(function () { var deferred = m.deferred() - deferred.promise["catch"](function() {return "foo"}).then(function(data) {value = data}) + var value + + deferred.promise + .catch(function () { return "foo" }) + .then(function (data) { value = data }) + deferred.reject("test") return value === "foo" }) - test(function() { + + test(function () { + var deferred = m.deferred() var value1, value2 - var deferred = m.deferred() - deferred.promise.then(function() {throw new Error()}).then(function() {value1 = 1}, function(data) {value2 = data}) + + deferred.promise + .then(function () { throw new Error() }) + .then(function () { value1 = 1 }, function (data) { value2 = data }) + deferred.resolve("test") return value1 === undefined && value2 instanceof Error }) - test(function() { - //Let unchecked exceptions bubble up in order to allow meaningful error messages in common cases like null reference exceptions due to typos - //An unchecked exception is defined as an object that is a subclass of Error (but not a direct instance of Error itself) - basically anything that can be thrown without an explicit `throw` keyword and that we'd never want to programmatically manipulate. In other words, an unchecked error is one where we only care about its line number and where the only reasonable way to deal with it is to change the buggy source code that caused the error to be thrown in the first place. - //By contrast, a checked exception is defined as anything that is explicitly thrown via the `throw` keyword and that can be programmatically handled, for example to display a validation error message on the UI. If an exception is a subclass of Error for whatever reason, but it is meant to be handled as a checked exception (i.e. follow the rejection rules for A+), it can be rethrown as an instance of Error - //This test tests two implementation details that differ from the Promises/A+ spec: - //1) A+ requires the `then` callback to be called in a different event loop from the resolve call, i.e. it must be asynchronous (this requires a setImmediate polyfill, which cannot be implemented in a reasonable way for Mithril's purpose - the possible polyfills are either too big or too slow) - //2) A+ swallows exceptions in a unrethrowable way, i.e. it's not possible to see default error messages on the console for runtime errors thrown from within a promise chain - var value1, value2, value3 + + test(function () { + // Let unchecked exceptions bubble up in order to allow meaningful error + // messages in common cases like null reference exceptions due to typos + // + // An unchecked exception is defined as an object that is a subclass of + // Error (but not a direct instance of Error itself) - basically + // anything that can be thrown without an explicit `throw` keyword and + // that we'd never want to programmatically manipulate. In other words, + // an unchecked error is one where we only care about its line number + // and where the only reasonable way to deal with it is to change the + // buggy source code that caused the error to be thrown in the first + // place. + // + // By contrast, a checked exception is defined as anything that is + // explicitly thrown via the `throw` keyword and that can be + // programmatically handled, for example to display a validation error + // message on the UI. If an exception is a subclass of Error for + // whatever reason, but it is meant to be handled as a checked exception + // (i.e. follow the rejection rules for A+), it can be rethrown as an + // instance of Error + // + // This test tests two implementation details that differ from the + // Promises/A+ spec: + // + // 1) A+ requires the `then` callback to be called in a different event + // loop from the resolve call, i.e. it must be asynchronous (this + // requires a setImmediate polyfill, which cannot be implemented in a + // reasonable way for Mithril's purpose - the possible polyfills are + // either too big or too slow) + // + // 2) A+ swallows exceptions in a unrethrowable way, i.e. it's not + // possible to see default error messages on the console for runtime + // errors thrown from within a promise chain var deferred = m.deferred() + var value1, value2, value3 + try { deferred.promise - .then(function() {foo.bar.baz}) //throws ReferenceError - .then(function() {value1 = 1}, function(data) {value2 = data}) + /* eslint-disable no-undef */ + // throws ReferenceError + .then(function () { return foo.bar.baz }) + /* eslint-enable no-undef */ + .then( + function () { value1 = 1 }, + function (data) { value2 = data } + ) deferred.resolve("test") + } catch (e) { + value3 = e } - catch (e) {value3 = e} - return value1 === undefined && value2 === undefined && (value3 instanceof ReferenceError || value3 instanceof TypeError) + + return value1 === undefined && + value2 === undefined && + (value3 instanceof ReferenceError || value3 instanceof TypeError) }) - test(function() { + + test(function () { var deferred1 = m.deferred() var deferred2 = m.deferred() var value1, value2 - deferred1.promise.then(function(data) { + deferred1.promise.then(function (data) { value1 = data return deferred2.promise - }).then(function(data) { + }).then(function (data) { value2 = data }) deferred1.resolve(1) deferred2.resolve(2) return value1 === 1 && value2 === 2 }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/80 - var deferred = m.deferred(), value + + test(function () { + // https://github.com/lhorie/mithril.js/issues/80 + var deferred = m.deferred() + var value + deferred.resolve(1) - deferred.promise.then(function(data) { + deferred.promise.then(function (data) { value = data }) + return value === 1 }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/80 - var deferred = m.deferred(), value + + test(function () { + // https://github.com/lhorie/mithril.js/issues/80 + var deferred = m.deferred() + var value + deferred.reject(1) - deferred.promise.then(null, function(data) { + deferred.promise.then(null, function (data) { value = data }) + return value === 1 }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/80 - var deferred = m.deferred(), value + + test(function () { + // https://github.com/lhorie/mithril.js/issues/80 + var deferred = m.deferred() + var value deferred.resolve(1) deferred.resolve(2) - deferred.promise.then(function(data) { + deferred.promise.then(function (data) { value = data }) return value === 1 }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/80 - var deferred = m.deferred(), value - deferred.promise.then(function(data) { + + test(function () { + // https://github.com/lhorie/mithril.js/issues/80 + var deferred = m.deferred() + var value + deferred.promise.then(function (data) { value = data }) deferred.resolve(1) deferred.resolve(2) return value === 1 }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/80 - var deferred = m.deferred(), value1, value2 - deferred.promise.then(function(data) { + + test(function () { + // https://github.com/lhorie/mithril.js/issues/80 + var deferred = m.deferred() + var value1, value2 + deferred.promise.then(function (data) { value1 = data - }, function(data) { + }, function (data) { value2 = data }) deferred.resolve(1) deferred.reject(2) return value1 === 1 && value2 === undefined }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/80 - var deferred = m.deferred(), value1, value2 - deferred.promise.then(function(data) { + + test(function () { + // https://github.com/lhorie/mithril.js/issues/80 + var deferred = m.deferred() + var value1, value2 + deferred.promise.then(function (data) { value1 = data - }, function(data) { + }, function (data) { value2 = data }) deferred.reject(1) deferred.resolve(2) return value1 === undefined && value2 === 1 }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/80 - var deferred = m.deferred(), value - deferred.promise.then(null, function(data) { + + test(function () { + // https://github.com/lhorie/mithril.js/issues/80 + var deferred = m.deferred() + var value + deferred.promise.then(null, function (data) { value = data }) deferred.reject(1) deferred.reject(2) return value === 1 }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/85 - var deferred = m.deferred(), value + + test(function () { + // https://github.com/lhorie/mithril.js/issues/85 + var deferred = m.deferred() + var value deferred.resolve() - deferred.promise.then(function() { + deferred.promise.then(function () { value = 1 }) return value === 1 }) - test(function() { - //https://github.com/lhorie/mithril.js/issues/85 - var deferred = m.deferred(), value + + test(function () { + // https://github.com/lhorie/mithril.js/issues/85 + var deferred = m.deferred() + var value deferred.reject() - deferred.promise.then(null, function() { + deferred.promise.then(null, function () { value = 1 }) return value === 1 }) - test(function() { + + test(function () { var deferred = m.deferred() deferred.resolve(1) return deferred.promise() === 1 }) - test(function() { + + test(function () { var deferred = m.deferred() - var promise = deferred.promise.then(function(data) {return data + 1}) + var promise = deferred.promise.then(function (data) { return data + 1 }) deferred.resolve(1) return promise() === 2 }) - test(function() { + + test(function () { var deferred = m.deferred() deferred.reject(1) return deferred.promise() === undefined }) - //m.sync - test(function() { + // m.sync + test(function () { var value var deferred1 = m.deferred() var deferred2 = m.deferred() - m.sync([deferred1.promise, deferred2.promise]).then(function(data) {value = data}) + + m.sync([deferred1.promise, deferred2.promise]) + .then(function (data) { value = data }) + deferred1.resolve("test") deferred2.resolve("foo") return value[0] === "test" && value[1] === "foo" }) - test(function() { + + test(function () { var value var deferred1 = m.deferred() var deferred2 = m.deferred() - m.sync([deferred1.promise, deferred2.promise]).then(function(data) {value = data}) + + m.sync([deferred1.promise, deferred2.promise]) + .then(function (data) { value = data }) + deferred2.resolve("foo") deferred1.resolve("test") return value[0] === "test" && value[1] === "foo" }) - test(function() { + + test(function () { var value var deferred = m.deferred() - m.sync([deferred.promise])["catch"](function(data) {value = data}) + m.sync([deferred.promise]).catch(function (data) { value = data }) deferred.reject("fail") return value[0] === "fail" }) - test(function() { + + test(function () { var value = 1 - m.sync([]).then(function() {value = 2}) + m.sync([]).then(function () { value = 2 }) return value === 2 }) - test(function() { + + test(function () { var success - m.sync([]).then(function(value) {success = value instanceof Array}) + m.sync([]).then(function (value) { success = value instanceof Array }) return success }) - //m.startComputation/m.endComputation - test(function() { + // m.startComputation/m.endComputation + test(function () { mock.requestAnimationFrame.$resolve() var root = mock.document.createElement("div") var controller = m.mount(root, { - controller: function() {}, - view: function(ctrl) {return ctrl.value} + controller: function () {}, + view: function (ctrl) { return ctrl.value } }) mock.requestAnimationFrame.$resolve() @@ -4353,44 +5513,53 @@ function testMithril(mock) { }) // config context - test(function() { + test(function () { var root = mock.document.createElement("div") - var success = false; - m.render(root, m("div", {config: function(elem, isInitialized, ctx) {ctx.data=1}})); - m.render(root, m("div", {config: function(elem, isInitialized, ctx) {success = ctx.data===1}})); - return success; + var success = false + + m.render(root, m("div", { + config: function (elem, isInit, ctx) { ctx.data = 1 } + })) + + m.render(root, m("div", { + config: function (elem, isInit, ctx) { success = ctx.data === 1 } + })) + + return success }) // more complex config context - test(function() { + test(function () { var root = mock.document.createElement("div") - var idx = 0; - var success = true; - var statefulConfig = function(elem, isInitialized, ctx) {ctx.data=idx++} - var node = m("div", {config: statefulConfig}); - m.render(root, [node, node]); + var idx = 0 + var success = true + function statefulConfig(elem, isInit, ctx) { ctx.data = idx++ } + var node = m("div", {config: statefulConfig}) + m.render(root, [node, node]) - idx = 0; - var checkConfig = function(elem, isInitialized, ctx) { + idx = 0 + + function checkConfig(elem, isInit, ctx) { success = success && (ctx.data === idx++) } - node = m("div", {config: checkConfig}); - m.render(root, [node, node]); - return success; + + node = m("div", {config: checkConfig}) + m.render(root, [node, node]) + + return success }) - //console.log presence - test(function() { + // console.log presence + test(function () { return m.deps.factory.toString().indexOf("console") < 0 }) - test(function() { + test(function () { return m.deps.factory.toString().indexOf("document.write") < 0 }) -} -//mock -testMithril(mock.window); - -test.print(function(value) {console.log(value)}) + test.print(function (value) { + console.log(value) // eslint-disable-line no-console + }) +})() diff --git a/tests/mock.js b/tests/mock.js index c1a8e88e..ee39d861 100644 --- a/tests/mock.js +++ b/tests/mock.js @@ -1,40 +1,49 @@ -if (!Array.prototype.indexOf) { - Array.prototype.indexOf = function (item) { - for (var i = 0; i < this.length; i++) { - if (this[i] === item) return i - } - return -1 - } -} -if (!Array.prototype.map) { - Array.prototype.map = function (callback) { - var results = [] - for (var i = 0; i < this.length; i++) { - results[i] = callback(this[i], i, this) - } - return results - } -} -if (!Array.prototype.filter) { - Array.prototype.filter = function (callback) { - var results = [] - for (var i = 0; i < this.length; i++) { - if (callback(this[i], i, this)) results.push(this[i]) - } - return results - } -} -if (!Object.keys) { - Object.keys = function () { - var keys = [] - for (var i in this) keys.push(i) - return keys - } -} +(function (global) { // eslint-disable-line max-statements + "use strict" -var mock = {} -mock.window = (function () { - var window = {} + /* eslint-disable no-extend-native */ + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (item) { + for (var i = 0; i < this.length; i++) { + if (this[i] === item) return i + } + return -1 + } + } + + if (!Array.prototype.map) { + Array.prototype.map = function (callback) { + var results = [] + for (var i = 0; i < this.length; i++) { + results[i] = callback(this[i], i, this) + } + return results + } + } + + if (!Array.prototype.filter) { + Array.prototype.filter = function (callback) { + var results = [] + for (var i = 0; i < this.length; i++) { + if (callback(this[i], i, this)) results.push(this[i]) + } + return results + } + } + + if (!Object.keys) { + Object.keys = function () { + var keys = [] + for (var i in this) if ({}.hasOwnProperty.call(this, i)) { + keys.push(i) + } + return keys + } + } + /* eslint-enable no-extend-native */ + + var window = global.mock = {window: window} + window.window = window window.document = {} window.document.childNodes = [] window.document.createElement = function (tag) { @@ -46,6 +55,7 @@ mock.window = (function () { appendChild: window.document.appendChild, removeChild: window.document.removeChild, replaceChild: window.document.replaceChild, + insertBefore: function (node, reference) { node.parentNode = this var referenceIndex = this.childNodes.indexOf(reference) @@ -54,15 +64,18 @@ mock.window = (function () { if (referenceIndex < 0) this.childNodes.push(node) else this.childNodes.splice(referenceIndex, 0, node) }, + insertAdjacentHTML: function (position, html) { - //todo: accept markup + // todo: accept markup if (position === "beforebegin") { - this.parentNode.insertBefore(window.document.createTextNode(html), this) - } - else if (position === "beforeend") { + this.parentNode.insertBefore( + window.document.createTextNode(html), + this) + } else if (position === "beforeend") { this.appendChild(window.document.createTextNode(html)) } }, + setAttribute: function (name, value) { this[name] = value.toString() }, @@ -70,7 +83,7 @@ mock.window = (function () { this.namespaceURI = namespace this[name] = value.toString() }, - getAttribute: function (name, value) { + getAttribute: function (name) { return this[name] }, addEventListener: function () {}, @@ -104,16 +117,18 @@ mock.window = (function () { this.childNodes.splice(index, 1) child.parentNode = null } - //getElementsByTagName is only used by JSONP tests, it's not required by Mithril + // getElementsByTagName is only used by JSONP tests, it's not required by + // Mithril window.document.getElementsByTagName = function (name){ name = name.toLowerCase() var out = [] - var traverse = function (node){ + function traverse(node) { if (node.childNodes && node.childNodes.length > 0){ node.childNodes.map(function (curr){ - if (curr.nodeName.toLowerCase() === name) + if (curr.nodeName.toLowerCase() === name) { out.push(curr) + } traverse(curr) }) } @@ -136,8 +151,9 @@ mock.window = (function () { callback() } } + window.XMLHttpRequest = (function () { - var request = function () { + function XMLHttpRequest() { this.$headers = {} this.setRequestHeader = function (key, value) { this.$headers[key] = value @@ -150,21 +166,28 @@ mock.window = (function () { this.responseText = JSON.stringify(this) this.readyState = 4 this.status = 200 - request.$instances.push(this) + XMLHttpRequest.$instances.push(this) } } - request.$instances = [] - return request - }()) - window.location = {search: "", pathname: "", hash: ""}, + XMLHttpRequest.$instances = [] + return XMLHttpRequest + })() + + window.location = {search: "", pathname: "", hash: ""} + window.history = {} window.history.$$length = 0 + window.history.pushState = function (data, title, url) { window.history.$$length++ - window.location.pathname = window.location.search = window.location.hash = url - }, - window.history.replaceState = function (data, title, url) { - window.location.pathname = window.location.search = window.location.hash = url + window.location.pathname = + window.location.search = + window.location.hash = url } - return window -}()) + + window.history.replaceState = function (data, title, url) { + window.location.pathname = + window.location.search = + window.location.hash = url + } +})(this) diff --git a/tests/npm-debug.log b/tests/npm-debug.log deleted file mode 100644 index 2fc27644..00000000 --- a/tests/npm-debug.log +++ /dev/null @@ -1,19 +0,0 @@ -0 info it worked if it ends with ok -1 verbose cli [ 'c:\\Program Files\\nodejs\\node.exe', -1 verbose cli 'c:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js', -1 verbose cli 'test' ] -2 info using npm@1.4.3 -3 info using node@v0.10.26 -4 error Error: ENOENT, open 'C:\Users\Leo\Desktop\shared\work\mithril.js\tests\package.json' -5 error If you need help, you may report this *entire* log, -5 error including the npm and node versions, at: -5 error -6 error System Windows_NT 6.1.7601 -7 error command "c:\\Program Files\\nodejs\\node.exe" "c:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "test" -8 error cwd C:\Users\Leo\Desktop\shared\work\mithril.js\tests -9 error node -v v0.10.26 -10 error npm -v 1.4.3 -11 error path C:\Users\Leo\Desktop\shared\work\mithril.js\tests\package.json -12 error code ENOENT -13 error errno 34 -14 verbose exit [ 34, true ] diff --git a/tests/svg.html b/tests/svg.html deleted file mode 100644 index b57adf93..00000000 --- a/tests/svg.html +++ /dev/null @@ -1,97 +0,0 @@ - - - - SVG test - - - -

Since it's not possible to test SVG functionality from a NodeJS environment, this page can be used to test it in a browser.

-

This page should contain:

- -

The links should open in a new tab. All items should display title tooltips when hovered over.

- -
- - - - diff --git a/tests/test.js b/tests/test.js index 992d6551..4a63552b 100644 --- a/tests/test.js +++ b/tests/test.js @@ -1,28 +1,38 @@ -if (!this.console) { - var log = function (value) { document.write("
" + value + "
") } - this.console = {log: log, error: log} -} +/* eslint-env browser */ -function test(condition) { - test.total++ +(function (global) { + "use strict" - try { - if (!condition()) throw new Error("failed") + function log(value) { + document.write("
" + value + "
") } - catch (e) { - console.error(e) - test.failures.push(condition) - } -} -test.total = 0 -test.failures = [] -test.print = function (print) { - for (var i = 0; i < test.failures.length; i++) { - print(test.failures[i].toString()) - } - print("tests: " + test.total + "\nfailures: " + test.failures.length) - if (test.failures.length > 0) { - throw new Error(test.failures.length + " tests did not pass") + if (!global.console) { + global.console = {log: log, error: log} } -} + + global.test = test + function test(condition) { + test.total++ + + try { + if (!condition()) throw new Error("failed") + } catch (e) { + console.error(e) // eslint-disable-line no-console + test.failures.push(condition) + } + } + test.total = 0 + test.failures = [] + test.print = function (print) { + for (var i = 0; i < test.failures.length; i++) { + print(test.failures[i].toString()) + } + + print("tests: " + test.total + "\nfailures: " + test.failures.length) + + if (test.failures.length > 0) { + throw new Error(test.failures.length + " tests did not pass") + } + } +})(this) diff --git a/tests/trust-test.html b/tests/trust-test.html deleted file mode 100644 index e69de29b..00000000