'use strict'; describe('jqLite', function() { var scope, a, b, c, document; // Checks if jQuery 2.1 is used. function isJQuery21() { if (_jqLiteMode) return false; var jQueryVersionParts = _jQuery.fn.jquery.split('.'); return jQueryVersionParts[0] + '.' + jQueryVersionParts[1] === '2.1'; } // Checks if jQuery 2.x is used. function isJQuery2x() { if (_jqLiteMode) return false; var jQueryVersionParts = _jQuery.fn.jquery.split('.'); return jQueryVersionParts[0] === '2'; } beforeEach(module(provideLog)); beforeEach(function() { a = jqLite('
A
')[0]; b = jqLite('
B
')[0]; c = jqLite('
C
')[0]; }); beforeEach(inject(function($rootScope) { document = window.document; scope = $rootScope; jasmine.addMatchers({ toJqEqual: function() { return { compare: function(_actual_, expected) { var msg = 'Unequal length'; var message = function() {return msg;}; var value = _actual_ && expected && _actual_.length === expected.length; for (var i = 0; value && i < expected.length; i++) { var actual = jqLite(_actual_[i])[0]; var expect = jqLite(expected[i])[0]; value = value && equals(expect, actual); msg = 'Not equal at index: ' + i + ' - Expected: ' + expect + ' - Actual: ' + actual; } return { pass: value, message: message }; } }; } }); })); afterEach(function() { dealoc(a); dealoc(b); dealoc(c); }); it('should be jqLite when jqLiteMode is on, otherwise jQuery', function() { expect(jqLite).toBe(_jqLiteMode ? JQLite : _jQuery); }); describe('construction', function() { it('should allow construction with text node', function() { var text = a.firstChild; var selected = jqLite(text); expect(selected.length).toEqual(1); expect(selected[0]).toEqual(text); }); it('should allow construction with html', function() { var nodes = jqLite('
1
2'); expect(nodes[0].parentNode).toBeDefined(); expect(nodes[0].parentNode.nodeType).toBe(11); /** Document Fragment **/ expect(nodes[0].parentNode).toBe(nodes[1].parentNode); expect(nodes.length).toEqual(2); expect(nodes[0].innerHTML).toEqual('1'); expect(nodes[1].innerHTML).toEqual('2'); }); it('should allow construction of html with leading whitespace', function() { var nodes = jqLite(' \n\r \r\n
1
2'); expect(nodes[0].parentNode).toBeDefined(); expect(nodes[0].parentNode.nodeType).toBe(11); /** Document Fragment **/ expect(nodes[0].parentNode).toBe(nodes[1].parentNode); expect(nodes.length).toBe(2); expect(nodes[0].innerHTML).toBe('1'); expect(nodes[1].innerHTML).toBe('2'); }); // This is not working correctly in jQuery prior to v2.2. // See https://github.com/jquery/jquery/issues/1987 for details. it('should properly handle dash-delimited node names', function() { if (isJQuery21()) return; var nodeNames = 'thead tbody tfoot colgroup caption tr th td div kung'.split(' '); var nodeNamesTested = 0; var nodes, customNodeName; forEach(nodeNames, function(nodeName) { var customNodeName = nodeName + '-foo'; var nodes = jqLite('<' + customNodeName + '>Hello, world !'); expect(nodes.length).toBe(1); expect(nodeName_(nodes)).toBe(customNodeName); expect(nodes.html()).toBe('Hello, world !'); nodeNamesTested++; }); expect(nodeNamesTested).toBe(10); }); it('should allow creation of comment tags', function() { var nodes = jqLite(''); expect(nodes.length).toBe(1); expect(nodes[0].nodeType).toBe(8); }); it('should allow creation of script tags', function() { var nodes = jqLite(''); expect(nodes.length).toBe(1); expect(nodes[0].tagName.toUpperCase()).toBe('SCRIPT'); }); it('should wrap document fragment', function() { var fragment = jqLite(document.createDocumentFragment()); expect(fragment.length).toBe(1); expect(fragment[0].nodeType).toBe(11); }); it('should allow construction of