2014-04-26 23:07:28 +03:00
|
|
|
/* global $: false */
|
2011-09-08 13:56:29 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
if (window.jQuery) {
|
|
|
|
|
|
2011-10-07 11:27:49 -07:00
|
|
|
describe('jQuery patch', function() {
|
2011-09-08 13:56:29 -07:00
|
|
|
|
|
|
|
|
var doc = null;
|
|
|
|
|
var divSpy = null;
|
|
|
|
|
var spy1 = null;
|
|
|
|
|
var spy2 = null;
|
|
|
|
|
|
2011-10-07 11:27:49 -07:00
|
|
|
beforeEach(function() {
|
2011-09-08 13:56:29 -07:00
|
|
|
divSpy = jasmine.createSpy('div.$destroy');
|
|
|
|
|
spy1 = jasmine.createSpy('span1.$destroy');
|
|
|
|
|
spy2 = jasmine.createSpy('span2.$destroy');
|
|
|
|
|
doc = $('<div><span class=first>abc</span><span class=second>xyz</span></div>');
|
2013-06-19 20:52:50 +01:00
|
|
|
doc.find('span.first').on('$destroy', spy1);
|
|
|
|
|
doc.find('span.second').on('$destroy', spy2);
|
2011-09-08 13:56:29 -07:00
|
|
|
});
|
|
|
|
|
|
2011-10-07 11:27:49 -07:00
|
|
|
afterEach(function() {
|
2011-09-08 13:56:29 -07:00
|
|
|
expect(divSpy).not.toHaveBeenCalled();
|
|
|
|
|
|
|
|
|
|
expect(spy1).toHaveBeenCalled();
|
2016-03-13 13:20:30 +01:00
|
|
|
expect(spy1).toHaveBeenCalledTimes(1);
|
2011-09-08 13:56:29 -07:00
|
|
|
expect(spy2).toHaveBeenCalled();
|
2016-03-13 13:20:30 +01:00
|
|
|
expect(spy2).toHaveBeenCalledTimes(1);
|
2011-09-08 13:56:29 -07:00
|
|
|
});
|
|
|
|
|
|
2017-09-20 14:02:53 +02:00
|
|
|
describe('$destroy event', function() {
|
2011-09-08 13:56:29 -07:00
|
|
|
|
2011-10-07 11:27:49 -07:00
|
|
|
it('should fire on remove()', function() {
|
2011-09-08 13:56:29 -07:00
|
|
|
doc.find('span').remove();
|
|
|
|
|
});
|
|
|
|
|
|
2011-10-07 11:27:49 -07:00
|
|
|
it('should fire on replaceWith()', function() {
|
2011-09-08 13:56:29 -07:00
|
|
|
doc.find('span').replaceWith('<b>bla</b>');
|
|
|
|
|
});
|
|
|
|
|
|
2011-10-07 11:27:49 -07:00
|
|
|
it('should fire on replaceAll()', function() {
|
2011-09-08 13:56:29 -07:00
|
|
|
$('<b>bla</b>').replaceAll(doc.find('span'));
|
|
|
|
|
});
|
|
|
|
|
|
2011-10-07 11:27:49 -07:00
|
|
|
it('should fire on empty()', function() {
|
2011-09-08 13:56:29 -07:00
|
|
|
doc.empty();
|
|
|
|
|
});
|
|
|
|
|
|
2013-04-30 11:29:07 +02:00
|
|
|
it('should fire on html(param)', function() {
|
2011-09-08 13:56:29 -07:00
|
|
|
doc.html('abc');
|
|
|
|
|
});
|
2013-04-30 11:29:07 +02:00
|
|
|
|
|
|
|
|
it('should fire on html(\'\')', function() {
|
|
|
|
|
doc.html('');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('jQuery patch eagerness', function() {
|
|
|
|
|
|
|
|
|
|
var doc = null;
|
|
|
|
|
var divSpy = null;
|
|
|
|
|
var spy1 = null;
|
|
|
|
|
var spy2 = null;
|
|
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
|
divSpy = jasmine.createSpy('div.$destroy');
|
|
|
|
|
spy1 = jasmine.createSpy('span1.$destroy');
|
|
|
|
|
spy2 = jasmine.createSpy('span2.$destroy');
|
|
|
|
|
doc = $('<div><span class=first>abc</span><span class=second>xyz</span></div>');
|
2014-04-22 15:31:22 +02:00
|
|
|
doc.find('span.first').on('$destroy', spy1);
|
|
|
|
|
doc.find('span.second').on('$destroy', spy2);
|
2013-04-30 11:29:07 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
|
expect(divSpy).not.toHaveBeenCalled();
|
|
|
|
|
expect(spy1).not.toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
|
2017-09-20 14:02:53 +02:00
|
|
|
describe('$destroy event is not invoked in too many cases', function() {
|
2013-04-30 11:29:07 +02:00
|
|
|
|
|
|
|
|
it('should fire only on matched elements on remove(selector)', function() {
|
|
|
|
|
doc.find('span').remove('.second');
|
|
|
|
|
expect(spy2).toHaveBeenCalled();
|
2016-03-13 13:20:30 +01:00
|
|
|
expect(spy2).toHaveBeenCalledTimes(1);
|
2013-04-30 11:29:07 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not fire on html()', function() {
|
|
|
|
|
doc.html();
|
|
|
|
|
expect(spy2).not.toHaveBeenCalled();
|
|
|
|
|
});
|
2011-09-08 13:56:29 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|