From 41cfda2719ee07e5a0937942a01d7c5ec048f3f6 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Fri, 13 May 2016 07:03:01 -0400 Subject: [PATCH] more component lifecycle tests --- README.md | 2 +- render/tests/test-component.js | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3c2ff7a0..13a4213e 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Mithril's `config` method is now replaced by several lifecycle methods to improv ## Robustness -There are over 2100 assertions in the test suite, and tests cover even difficult-to-test things like `location.href`, `element.innerHTML` and `XMLHttpRequest` usage. +There are over 2200 assertions in the test suite, and tests cover even difficult-to-test things like `location.href`, `element.innerHTML` and `XMLHttpRequest` usage. ## Modularity diff --git a/render/tests/test-component.js b/render/tests/test-component.js index c9f72ae4..87c5e00e 100644 --- a/render/tests/test-component.js +++ b/render/tests/test-component.js @@ -272,6 +272,24 @@ o.spec("component", function() { } }) }) + o("does not calls oninit on redraw", function() { + var init = o.spy() + var component = { + view: function() { + return {tag: "div", attrs: {id: "a"}, text: "b"} + }, + oninit: init, + } + + function view() { + return {tag: component} + } + + render(root, view()) + render(root, view()) + + o(init.callCount).equals(1) + }) o("calls oncreate", function() { var called = 0 var component = { @@ -295,6 +313,24 @@ o.spec("component", function() { o(root.firstChild.attributes["id"].nodeValue).equals("a") o(root.firstChild.firstChild.nodeValue).equals("b") }) + o("does not calls oncreate on redraw", function() { + var create = o.spy() + var component = { + view: function() { + return {tag: "div", attrs: {id: "a"}, text: "b"} + }, + oncreate: create, + } + + function view() { + return {tag: component} + } + + render(root, view()) + render(root, view()) + + o(create.callCount).equals(1) + }) o("calls oncreate when returning fragment", function() { var called = 0 var component = {