Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Use afterMutation helper #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions test/can-ejs_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var CanList = require("can-list");
var canFrag = require("can-util/dom/frag/frag");
var canCompute = require("can-compute");
var domMutate = require("can-util/dom/mutate/mutate");
var domEvents = require('can-util/dom/events/events');
var globals = require('can-globals');

QUnit.module('can-ejs, rendering', {
setup: function () {
Expand Down Expand Up @@ -1374,22 +1376,33 @@ test('outputting array of attributes', function () {
equal(div.children[0].getAttribute('data-test2'), 'value2', 'second value');
equal(div.children[0].getAttribute('data-test3'), 'value3', 'third value');
});
test('_bindings removed when element removed', function () {
var template = EJS('<div id="game"><% if(game.attr("league")) { %><%= game.attr("name") %><% } %></div>'),
game = new CanMap({
'name': 'Fantasy Baseball',
'league': 'Malamonsters'
});
var frag = template({
game: game

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('_bindings removed when element removed', function (assert) {
var done = assert.async();
var div = document.getElementById("qunit-fixture");
var game = new CanMap({
'name': 'Fantasy Baseball',
'league': 'Malamonsters'
});
var template = EJS('<div id="game"><% if(game.attr("league")) { %><%= game.attr("name") %><% } %></div>');
var frag = template({game: game});

div.appendChild(frag);
domMutate.removeChild.call(div, div.firstChild);
stop();
setTimeout(function () {
start();
equal(game.__bindEvents._lifecycleBindings, 0, 'No bindings left');
}, 100);
afterMutation(function () {
assert.equal(game.__bindEvents._lifecycleBindings, 0, 'No bindings left');
done();
});
});