Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should listen to delegate events on the element even before it\'s created', function() {
comp = new Component({}, false);
var listener = sinon.stub();
comp.delegate('click', '.foo', listener);
var element = document.createElement('div');
dom.append(element, '<div class="foo"></div>');
comp.element = element;
dom.triggerEvent(element.querySelector('.foo'), 'click');
assert.strictEqual(1, listener.callCount);
});
it('should not reatach delegate listeners that were detached when element changes', function() {
var CustomComponent = createCustomComponentClass('<div class="foo"></div>');
comp = new CustomComponent();
var listener = sinon.stub();
var handle = comp.delegate('click', '.foo', listener);
handle.removeListener();
var newElement = document.createElement('div');
comp.element = newElement;
dom.append(newElement, '<div class="foo"></div>');
dom.triggerEvent(newElement.querySelector('.foo'), 'click');
assert.strictEqual(0, listener.callCount);
});
convertHtmlToBrowserFormat_(htmlString) {
var element = document.createElement('div');
dom.append(element, htmlString);
return element.innerHTML;
}
if (newElement) {
this.component_.element = newElement;
return;
} else {
this.component_.element = document.createElement('div');
element = this.component_.element;
}
}
if (newElement) {
this.updateElementAttributes_(element, newElement);
newContent = newElement.childNodes;
}
dom.removeChildren(element);
dom.append(element, newContent);
}