From b85b6a02bbb2c61c8c685cd1dc6e64f6cff5fbc7 Mon Sep 17 00:00:00 2001 From: Chris Andrejewski Date: Thu, 9 Nov 2017 15:14:52 -0500 Subject: [PATCH 1/2] use afterMutation helper for test --- package.json | 1 + test/live-test.js | 39 +++++++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index e6d4532..c914ae0 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "can-view-target": "^3.1.0" }, "devDependencies": { + "can-globals": "^0.2.6", "can-list": "^3.2.0", "can-map": "^3.3.1", "detect-cyclic-packages": "^1.1.0", diff --git a/test/live-test.js b/test/live-test.js index d90d8e9..3bf5fc3 100644 --- a/test/live-test.js +++ b/test/live-test.js @@ -6,6 +6,7 @@ var nodeLists = require('can-view-nodelist'); var canBatch = require('can-event/batch/batch'); var Observation = require("can-observation"); var domEvents = require('can-util/dom/events/events'); +var globals = require('can-globals'); var QUnit = require('steal-qunit'); @@ -223,25 +224,36 @@ test('list with a compute that returns a list', function () { equal(spans.length, 3, 'there are 3 spans'); }); -test('text binding is memory safe (#666)', function () { - nodeLists.nodeMap.clear(); +function afterMutation (cb) { + var doc = globals.getKeyValue('document'); + var div = doc.createElement("div"); + domEvents.addEventListener.call(div, "inserted", function(){ + doc.body.removeChild(div); + setTimeout(cb, 5); + }); + setTimeout(function(){ + domMutate.appendChild.call(doc.body, div); + },10); +} - var div = document.createElement('div'), - span = document.createElement('span'), - text = compute(function () { - return 'foo'; - }); - div.appendChild(span); +test('text binding is memory safe (#666)', function (assert) { + var done = assert.async(); + var div = document.createElement('div'); + var span = document.createElement('span'); + var text = compute(function () { + return 'foo'; + }); + nodeLists.nodeMap.clear(); + div.appendChild(span); domMutate.appendChild.call(this.fixture, div); live.text(span, text, div); domMutate.removeChild.call(this.fixture, div); - stop(); - setTimeout(function () { - ok(!nodeLists.nodeMap.size, 'nothing in nodeMap'); - start(); - }, 100); + afterMutation(function () { + assert.ok(!nodeLists.nodeMap.size, 'nothing in nodeMap'); + done(); + }); }); test('html live binding handles getting a function from a compute',5, function(){ @@ -638,4 +650,3 @@ QUnit.test("events are torn down from correct list on change", function() { ok(!list.__bindEvents.add || list.__bindEvents.add.length === 0, "Add handler has been removed from list"); ok(filteredList.__bindEvents.add && filteredList.__bindEvents.add.length > 0, "Add handler has been added to filteredList"); }); - From 763b361e446005f169f782ce5e6e3f619423ce6a Mon Sep 17 00:00:00 2001 From: Chris Andrejewski Date: Fri, 17 Nov 2017 13:54:19 -0500 Subject: [PATCH 2/2] Use removed event directly --- test/live-test.js | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/test/live-test.js b/test/live-test.js index 3bf5fc3..338b5ef 100644 --- a/test/live-test.js +++ b/test/live-test.js @@ -224,18 +224,6 @@ test('list with a compute that returns a list', function () { equal(spans.length, 3, 'there are 3 spans'); }); -function afterMutation (cb) { - var doc = globals.getKeyValue('document'); - var div = doc.createElement("div"); - domEvents.addEventListener.call(div, "inserted", function(){ - doc.body.removeChild(div); - setTimeout(cb, 5); - }); - setTimeout(function(){ - domMutate.appendChild.call(doc.body, div); - },10); -} - test('text binding is memory safe (#666)', function (assert) { var done = assert.async(); var div = document.createElement('div'); @@ -250,7 +238,8 @@ test('text binding is memory safe (#666)', function (assert) { live.text(span, text, div); domMutate.removeChild.call(this.fixture, div); - afterMutation(function () { + + domEvents.addEventListener.call(div, 'removed', function () { assert.ok(!nodeLists.nodeMap.size, 'nothing in nodeMap'); done(); });