From eccd9bfbb3d63731814941789089e1c799005fb4 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Thu, 31 Mar 2011 01:34:24 -0700 Subject: add much needed whitespace to jqLiteSpec.js can we agree to put more white space into our code? I follow there rules for specs: - 1 blank line between sections of nontrivial it block - 2 blank lines between it blocks - 2 blank lines between describe blocks - 2 blank lines between beforeEach and afterEach - no blank line between describe and the first child it - no blank lines between two or more closing }); lines --- test/jqLiteSpec.js | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 3 deletions(-) (limited to 'test/jqLiteSpec.js') diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js index 8efead0a..3486fbbb 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -1,12 +1,13 @@ describe('jqLite', function(){ - var scope; - var a, b, c; + var scope, a, b, c; + beforeEach(function(){ a = jqLite('
A
')[0]; b = jqLite('
B
')[0]; c = jqLite('
C
')[0]; }); + beforeEach(function(){ scope = angular.scope(); this.addMatchers({ @@ -28,12 +29,14 @@ describe('jqLite', function(){ }); }); + afterEach(function(){ dealoc(a); dealoc(b); dealoc(c); }); + describe('construction', function(){ it('should allow construction with text node', function(){ var text = a.firstChild; @@ -42,6 +45,7 @@ describe('jqLite', function(){ expect(selected[0]).toEqual(text); }); + it('should allow construction with html', function(){ var nodes = jqLite('
1
2'); expect(nodes.length).toEqual(2); @@ -49,18 +53,21 @@ describe('jqLite', function(){ expect(nodes[1].innerHTML).toEqual('2'); }); + 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); @@ -68,6 +75,7 @@ describe('jqLite', function(){ }); }); + describe('scope', function() { it('should retrieve scope attached to the current element', function() { var element = jqLite('foo'); @@ -76,6 +84,7 @@ describe('jqLite', function(){ dealoc(element); }); + it('should walk up the dom to find scope', function() { var element = jqLite(''); var deepChild = jqLite(element[0].getElementsByTagName('b')[0]); @@ -84,6 +93,7 @@ describe('jqLite', function(){ dealoc(element); }); + it('should return undefined when no scope was found', function() { var element = jqLite(''); var deepChild = jqLite(element[0].getElementsByTagName('b')[0]); @@ -92,6 +102,7 @@ describe('jqLite', function(){ }); }); + describe('data', function(){ it('should set and get ande remove data', function(){ var selected = jqLite([a, b, c]); @@ -115,6 +126,7 @@ describe('jqLite', function(){ }); }); + describe('attr', function(){ it('shoul read wirite and remove attr', function(){ var selector = jqLite([a, b]); @@ -136,13 +148,18 @@ describe('jqLite', function(){ expect(jqLite(b).attr('prop')).toBeFalsy(); }); }); + + describe('class', function(){ + describe('hasClass', function(){ it('should check class', function(){ var selector = jqLite([a, b]); expect(selector.hasClass('abc')).toEqual(false); }); }); + + describe('addClass', function(){ it('should allow adding of class', function(){ var selector = jqLite([a, b]); @@ -151,6 +168,8 @@ describe('jqLite', function(){ expect(jqLite(b).hasClass('abc')).toEqual(true); }); }); + + describe('toggleClass', function(){ it('should allow toggling of class', function(){ var selector = jqLite([a, b]); @@ -172,6 +191,8 @@ describe('jqLite', function(){ }); }); + + describe('removeClass', function(){ it('should allow removal of class', function(){ var selector = jqLite([a, b]); @@ -182,6 +203,8 @@ describe('jqLite', function(){ }); }); }); + + describe('css', function(){ it('should set and read css', function(){ var selector = jqLite([a, b]); @@ -203,12 +226,15 @@ describe('jqLite', function(){ expect(jqLite(b).css('prop')).toBeFalsy(); }); }); + + describe('text', function(){ it('should return null on empty', function(){ expect(jqLite().length).toEqual(0); expect(jqLite().text()).toEqual(''); }); + it('should read/write value', function(){ var element = jqLite('
abc
'); expect(element.length).toEqual(1); @@ -218,6 +244,8 @@ describe('jqLite', function(){ expect(element.text()).toEqual('xyz'); }); }); + + describe('val', function(){ it('should read, write value', function(){ var input = jqLite(''); @@ -226,12 +254,15 @@ describe('jqLite', function(){ expect(input.val()).toEqual('abc'); }); }); + + describe('html', function(){ it('should return null on empty', function(){ expect(jqLite().length).toEqual(0); expect(jqLite().html()).toEqual(null); }); + it('should read/write value', function(){ var element = jqLite('
abc
'); expect(element.length).toEqual(1); @@ -242,6 +273,7 @@ describe('jqLite', function(){ }); }); + describe('bind', function(){ it('should bind to window on hashchange', function(){ if (jqLite.fn) return; // don't run in jQuery @@ -272,6 +304,7 @@ describe('jqLite', function(){ dealoc(jWindow); }); + it('should bind to all elements and return functions', function(){ var selected = jqLite([a, b]); var log = ''; @@ -285,6 +318,7 @@ describe('jqLite', function(){ }); }); + describe('replaceWith', function(){ it('should replaceWith', function(){ var root = jqLite('
').html('before-
after'); @@ -292,6 +326,8 @@ describe('jqLite', function(){ expect(div.replaceWith('span-bold-')).toEqual(div); expect(root.text()).toEqual('before-span-bold-after'); }); + + it('should replaceWith text', function(){ var root = jqLite('
').html('before-
after'); var div = root.find('div'); @@ -299,6 +335,8 @@ describe('jqLite', function(){ expect(root.text()).toEqual('before-text-after'); }); }); + + describe('children', function(){ it('should select non-text children', function(){ var root = jqLite('
').html('before-
after-'); @@ -307,6 +345,8 @@ describe('jqLite', function(){ expect(root.children()).toJqEqual([div, span]); }); }); + + describe('append', function(){ it('should append', function(){ var root = jqLite('
'); @@ -324,6 +364,8 @@ describe('jqLite', function(){ expect(root.children().length).toBe(0); }); }); + + describe('remove', function(){ it('should remove', function(){ var root = jqLite('
abc
'); @@ -332,6 +374,8 @@ describe('jqLite', function(){ expect(root.html()).toEqual(''); }); }); + + describe('after', function(){ it('should after', function(){ var root = jqLite('
'); @@ -339,6 +383,8 @@ describe('jqLite', function(){ expect(span.after('')).toEqual(span); expect(root.html().toLowerCase()).toEqual(''); }); + + it('should allow taking text', function(){ var root = jqLite('
'); var span = root.find('span'); @@ -346,6 +392,8 @@ describe('jqLite', function(){ expect(root.html().toLowerCase()).toEqual('abc'); }); }); + + describe('parent', function(){ it('should return parent or an empty set when no parent', function(){ var parent = jqLite('

abc

'), @@ -357,11 +405,15 @@ describe('jqLite', function(){ expect(child.parent().length).toBe(1); expect(child.parent()[0]).toBe(parent[0]); }); + + it('should return empty set when no parent', function(){ var element = jqLite('
abc
'); expect(element.parent()).toBeTruthy(); expect(element.parent().length).toEqual(0); }); + + it('should return empty jqLite object when parent is a document fragment', function() { //this is quite unfortunate but jQuery 1.5.1 behaves this way var fragment = document.createDocumentFragment(), @@ -372,6 +424,8 @@ describe('jqLite', function(){ expect(child.parent().length).toBe(0); }); }); + + describe('next', function(){ it('should return next sibling', function(){ var element = jqLite('
bi
'); @@ -380,6 +434,8 @@ describe('jqLite', function(){ expect(b.next()).toJqEqual([i]); }); }); + + describe('find', function(){ it('should find child by name', function(){ var root = jqLite('
text
'); @@ -388,5 +444,4 @@ describe('jqLite', function(){ expect(innerDiv.html()).toEqual('text'); }); }); - }); -- cgit v1.2.3