Browse files

Remove all the semicolons!

- change some expect(a == b).to.be.ok() into expect(a).to.be(b)
- fix some double defined vars
  • Loading branch information...
1 parent d73f5c7 commit ff5582439a4221ea047d8842ef6da715f51099a0 @arian arian committed May 17, 2012
Showing with 335 additions and 307 deletions.
  1. +4 −0 Makefile
  2. +3 −2 test/attributes.html
  3. +115 −118 test/attributes.js
  4. +3 −2 test/events.html
  5. +13 −10 test/events.js
  6. +1 −1 test/index.html
  7. +3 −2 test/insertion.html
  8. +85 −75 test/insertion.js
  9. +3 −2 test/list.html
  10. +31 −28 test/list.js
  11. +3 −2 test/nodes.html
  12. +71 −65 test/nodes.js
View
4 Makefile
@@ -14,4 +14,8 @@ test-server:
test-phantom:
@phantomjs ./test/phantom.js 'http://localhost:8080/attributes.html'
+ @phantomjs ./test/phantom.js 'http://localhost:8080/events.html'
+ @phantomjs ./test/phantom.js 'http://localhost:8080/insertion.html'
+ @phantomjs ./test/phantom.js 'http://localhost:8080/list.html'
+ @phantomjs ./test/phantom.js 'http://localhost:8080/nodes.html'
View
5 test/attributes.html
@@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>Nodes attributes tests</title>
- <link href="mocha.css" rel="stylesheet" type="text/css" media="screen"/>
+ <link href="mocha.css" rel="stylesheet" type="text/css" media="screen" />
<script src="mocha.js" type="text/javascript"></script>
<script>
@@ -20,8 +20,9 @@
</head>
<body>
-<a href="/">back</a>
+<a href="/">back</a>
<div id="mocha"></div>
+
</body>
</html>
View
233 test/attributes.js
@@ -1,20 +1,23 @@
"use strict";
+
var $ = require('../lib/attributes')
var expect = require('expect.js')
+
describe('attribute.js', function(){
+
// prepare the environment
beforeEach(function(){
- var body = document.getElementsByTagName('body')[0];
- var container = document.getElementById('container');
+ var body = document.getElementsByTagName('body')[0]
+ var container = document.getElementById('container')
if (!container){
- container = document.createElement('div');
- container.id = 'container';
- container.style.display = 'none';
- container.style.position = 'absolute';
- container.top = 0;
- container.left = 0;
+ container = document.createElement('div')
+ container.id = 'container'
+ container.style.display = 'none'
+ container.style.position = 'absolute'
+ container.top = 0
+ container.left = 0
}
- body.appendChild(container);
+ body.appendChild(container)
container.innerHTML = ['',
'<ul>',
'<li class="first">1</li>',
@@ -27,36 +30,30 @@ describe('attribute.js', function(){
'<option>1</option>',
'<option selected="selected">2</option>',
'</select>'
- ].join('');
+ ].join('')
})
describe('setAttribute', function(){
it('should set title attribute on the 2nd li', function(){
- var lis = document.getElementById('container').getElementsByTagName('li');
- var li = $(lis[1]);
- expect(li.getAttribute('title')).to.be('title');
- li.setAttribute('title', 'changed');
- expect(li.getAttribute('title')).to.be('changed');
+ var lis = document.getElementById('container').getElementsByTagName('li')
+ var li = $(lis[1])
+ expect(li.getAttribute('title')).to.be('title')
+ li.setAttribute('title', 'changed')
+ expect(li.getAttribute('title')).to.be('changed')
})
})
describe('getAttribute', function(){
it('should get correct attributes', function(){
- var lis = $(document.getElementById('container').getElementsByTagName('li'));
+ var lis = $(document.getElementById('container').getElementsByTagName('li'))
lis.handle(function(element, index){
switch (index){
- case 0:
- expect(this.getAttribute('class')).to.be('first');
- break;
- case 1:
- expect(this.getAttribute('title')).to.be('title');
- break;
- case 2:
- expect(this.getAttribute('id')).to.be('third');
- break;
+ case 0: expect(this.getAttribute('class')).to.be('first'); break
+ case 1: expect(this.getAttribute('title')).to.be('title'); break
+ case 2: expect(this.getAttribute('id')).to.be('third'); break
}
})
})
@@ -66,30 +63,30 @@ describe('attribute.js', function(){
describe('hasAttribute', function(){
it('should know if an element has an attribute or not', function(){
- var lis = document.getElementById('container').getElementsByTagName('li');
- var li = $(lis[0]);
- expect(li.hasAttribute('class')).to.be.ok();
- expect(li.hasAttribute('id')).to.be(false);
+ var lis = document.getElementById('container').getElementsByTagName('li')
+ var li = $(lis[0])
+ expect(li.hasAttribute('class')).to.be.ok()
+ expect(li.hasAttribute('id')).to.be(false)
})
it('should fallback in case hasAttribute is not present', function(){
- var lis = document.getElementById('container').getElementsByTagName('li');
- lis[0].hasAttribute = null;
- var li = $(lis[0]);
- expect(li.hasAttribute('class')).to.be.ok();
- expect(li.hasAttribute('id')).to.be(false);
+ var lis = document.getElementById('container').getElementsByTagName('li')
+ lis[0].hasAttribute = null
+ var li = $(lis[0])
+ expect(li.hasAttribute('class')).to.be.ok()
+ expect(li.hasAttribute('id')).to.be(false)
})
})
describe('removeAttribute', function(){
it('should correctly remove an attribute', function(){
- var lis = document.getElementById('container').getElementsByTagName('li');
- var li = $(lis[1]);
- expect(li.hasAttribute('title')).to.be.ok();
- li.removeAttribute('title');
- expect(li.hasAttribute('title')).to.be(false);
+ var lis = document.getElementById('container').getElementsByTagName('li')
+ var li = $(lis[1])
+ expect(li.hasAttribute('title')).to.be.ok()
+ li.removeAttribute('title')
+ expect(li.hasAttribute('title')).to.be(false)
})
})
@@ -99,151 +96,151 @@ describe('attribute.js', function(){
describe('should correctly handle common properties: ', function(){
it('handles type', function(){
- var input = $(document.getElementById('moo'));
- expect(input.type()).to.be('text');
- input.type('button');
- expect(input.type()).to.be('button');
+ var input = $(document.getElementById('moo'))
+ expect(input.type()).to.be('text')
+ input.type('button')
+ expect(input.type()).to.be('button')
})
it('handles value', function(){
- var input = $(document.getElementById('moo'));
- expect(input.value()).to.be('mootools');
- input.value('mootools rocks!');
- expect(input.value()).to.be('mootools rocks!');
+ var input = $(document.getElementById('moo'))
+ expect(input.value()).to.be('mootools')
+ input.value('mootools rocks!')
+ expect(input.value()).to.be('mootools rocks!')
})
it('handles name', function(){
- var input = $(document.getElementById('moo'));
- expect(input.name()).to.be('library');
- input.name('framework');
- expect(input.name()).to.be('framework');
+ var input = $(document.getElementById('moo'))
+ expect(input.name()).to.be('library')
+ input.name('framework')
+ expect(input.name()).to.be('framework')
})
it('handles href', function(){
- var link = $(document.getElementById('link'));
- expect(link.href().indexOf('#library') != -1).to.be.ok();
- link.href('#framework');
- expect(link.href().indexOf('#framework') != -1).to.be.ok();
+ var link = $(document.getElementById('link'))
+ expect(link.href().indexOf('#library') != -1).to.be.ok()
+ link.href('#framework')
+ expect(link.href().indexOf('#framework') != -1).to.be.ok()
})
it('handles title', function(){
- var lis = document.getElementById('container').getElementsByTagName('li');
- var li = $(lis[1]);
- expect(li.title()).to.be('title');
- li.title('mootools li');
- expect(li.title()).to.be('mootools li');
+ var lis = document.getElementById('container').getElementsByTagName('li')
+ var li = $(lis[1])
+ expect(li.title()).to.be('title')
+ li.title('mootools li')
+ expect(li.title()).to.be('mootools li')
})
})
describe('should correcly handle booleans: ', function(){
it('handles checked', function(){
- var input = $(document.getElementById('moo'));
- input.type('checkbox');
- input.checked(true);
- expect(input.checked()).to.be.ok();
- input.checked(false);
- expect(input.checked()).to.be(false);
+ var input = $(document.getElementById('moo'))
+ input.type('checkbox')
+ input.checked(true)
+ expect(input.checked()).to.be.ok()
+ input.checked(false)
+ expect(input.checked()).to.be(false)
})
it('handles disabled', function(){
- var input = $(document.getElementById('moo'));
- input.disabled(true);
- expect(input.disabled()).to.be.ok();
- input.disabled(false);
- expect(input.disabled()).to.be(false);
+ var input = $(document.getElementById('moo'))
+ input.disabled(true)
+ expect(input.disabled()).to.be.ok()
+ input.disabled(false)
+ expect(input.disabled()).to.be(false)
})
it('handles selected', function(){
var select = document.getElementById('mooselect'),
first = $(select.childNodes[0]),
- second = $(select.childNodes[1]);
- expect(first.selected()).to.be(false);
- expect(second.selected()).to.be.ok();
- first.selected(true);
- expect(first.selected()).to.be.ok();
- expect(second.selected()).to.be(false);
+ second = $(select.childNodes[1])
+ expect(first.selected()).to.be(false)
+ expect(second.selected()).to.be.ok()
+ first.selected(true)
+ expect(first.selected()).to.be.ok()
+ expect(second.selected()).to.be(false)
})
})
describe('handle className, classNames, id, tag', function(){
it('set new id', function(){
- var html = $(document.documentElement);
- html.id('newid');
- expect(html.id()).to.be('newid');
- html.id('html');
- expect(html.id()).to.be('html');
+ var html = $(document.documentElement)
+ html.id('newid')
+ expect(html.id()).to.be('newid')
+ html.id('html')
+ expect(html.id()).to.be('html')
})
it('can reset classnames with className', function(){
var lis = document.getElementById('container').getElementsByTagName('li'),
- li = $(lis[0]);
- expect(li.className()).to.be('first');
- li.className('ex first now second');
- expect(li.className()).to.be('ex first now second');
+ li = $(lis[0])
+ expect(li.className()).to.be('first')
+ li.className('ex first now second')
+ expect(li.className()).to.be('ex first now second')
})
it('has classnames method that return classes as an ordered array of string', function(){
var lis = document.getElementById('container').getElementsByTagName('li'),
- li = $(lis[0]);
- expect(li.classNames()).to.be.an(Array);
- expect(li.classNames().length).to.be(1);
- expect(li.classNames()[0]).to.be('first');
- li.className('once first now second');
- expect(li.classNames().length).to.be(4);
- var exp = ['once', 'first', 'now', 'second'].sort();
+ li = $(lis[0])
+ expect(li.classNames()).to.be.an(Array)
+ expect(li.classNames().length).to.be(1)
+ expect(li.classNames()[0]).to.be('first')
+ li.className('once first now second')
+ expect(li.classNames().length).to.be(4)
+ var exp = ['first', 'now', 'once', 'second']
for (var i = 0, max = 3; i < max; i++){
- expect(li.classNames()[i]).to.be(exp[i]);
+ expect(li.classNames()[i]).to.be(exp[i])
}
})
it('has a tag method that return the tag name', function(){
- expect($(document.documentElement).tag()).to.be('html');
+ expect($(document.documentElement).tag()).to.be('html')
})
- });
+ })
describe('implements has/add/removeClass:', function(){
it('can tell if an element has a class', function(){
- var lis = document.getElementById('container').getElementsByTagName('li');
- var li = $(lis[0]);
- expect(li.hasClass('first')).to.be.ok();
- expect(li.hasClass('mootools')).to.be(false);
+ var lis = document.getElementById('container').getElementsByTagName('li')
+ var li = $(lis[0])
+ expect(li.hasClass('first')).to.be.ok()
+ expect(li.hasClass('mootools')).to.be(false)
})
it('can add a class to an element', function(){
- var lis = document.getElementById('container').getElementsByTagName('li');
- var li = $(lis[0]);
- li.addClass('mootools');
- expect(li.hasClass('mootools')).to.be.ok();
- expect(li.hasClass('first')).to.be.ok();
+ var lis = document.getElementById('container').getElementsByTagName('li')
+ var li = $(lis[0])
+ li.addClass('mootools')
+ expect(li.hasClass('mootools')).to.be.ok()
+ expect(li.hasClass('first')).to.be.ok()
})
it('can remove a class from an element', function(){
- var lis = document.getElementById('container').getElementsByTagName('li');
- var li = $(lis[0]);
- li.removeClass('first');
- li.addClass('mootools');
- expect(li.hasClass('mootools')).to.be.ok();
- expect(li.hasClass('first')).to.be(false);
+ var lis = document.getElementById('container').getElementsByTagName('li')
+ var li = $(lis[0])
+ li.removeClass('first')
+ li.addClass('mootools')
+ expect(li.hasClass('mootools')).to.be.ok()
+ expect(li.hasClass('first')).to.be(false)
})
})
describe('expose a toString method', function(){
it('return a brief description of the tag, including id, class', function(){
- var lis = document.getElementById('container').getElementsByTagName('li');
- var li = $(lis[0]);
- li.id('LI');
- li.className('mootools');
- var desc = li.toString();
- expect(desc).to.be.a('string');
- expect(desc).to.be("li#LI.mootools");
+ var lis = document.getElementById('container').getElementsByTagName('li')
+ var li = $(lis[0])
+ li.id('LI')
+ li.className('mootools')
+ var desc = li.toString()
+ expect(desc).to.be.a('string')
+ expect(desc).to.be("li#LI.mootools")
})
})
View
5 test/events.html
@@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>Nodes events tests</title>
- <link href="mocha.css" rel="stylesheet" type="text/css" media="screen"/>
+ <link href="mocha.css" rel="stylesheet" type="text/css" media="screen" />
<script src="mocha.js" type="text/javascript"></script>
<script>
@@ -20,8 +20,9 @@
</head>
<body>
-<a href="/">back</a>
+<a href="/">back</a>
<div id="mocha"></div>
+
</body>
</html>
View
23 test/events.js
@@ -1,29 +1,32 @@
"use strict";
+
var $ = require('../lib/events')
var expect = require('expect.js')
+
describe('events.js', function(){
- var body = $(document.documentElement);
+
+ var body = $(document.documentElement)
describe('should implement Emit.on/off/emit', function(){
it('should allow event subscription', function(){
- var flag = false;
+ var flag = false
body.on('w00fz', function(){
- flag = true;
+ flag = true
})
- body.emit('w00fz');
- expect(flag).to.be.ok();
+ body.emit('w00fz')
+ expect(flag).to.be.ok()
})
it('should allow event de-subscription', function(){
- var flag = false;
+ var flag = false
var callback = function(){
- flag = true;
- };
+ flag = true
+ }
body.on('w00fz', callback)
body.off('w00fz', callback)
- body.emit('w00fz');
- expect(flag).to.be(false);
+ body.emit('w00fz')
+ expect(flag).to.be(false)
})
})
View
2 test/index.html
@@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>Nodes Tests</title>
- <link href="mocha.css" rel="stylesheet" type="text/css" media="screen"/>
+ <link href="mocha.css" rel="stylesheet" type="text/css" media="screen" />
<style>
li {
list-style-type: none;
View
5 test/insertion.html
@@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>Nodes insertion tests</title>
- <link href="mocha.css" rel="stylesheet" type="text/css" media="screen"/>
+ <link href="mocha.css" rel="stylesheet" type="text/css" media="screen" />
<script src="mocha.js" type="text/javascript"></script>
<script>
@@ -20,8 +20,9 @@
</head>
<body>
-<a href="/">back</a>
+<a href="/">back</a>
<div id="mocha"></div>
+
</body>
</html>
View
160 test/insertion.js
@@ -1,20 +1,23 @@
"use strict";
+
var $ = require('../lib/insertion')
var expect = require('expect.js')
+
describe('insertion.js', function(){
+
// prepare the environment
beforeEach(function(){
- var body = document.getElementsByTagName('body')[0];
- var container = document.getElementById('container');
+ var body = document.getElementsByTagName('body')[0]
+ var container = document.getElementById('container')
if (!container){
- container = document.createElement('div');
- container.id = 'container';
- container.style.display = 'none';
- container.style.position = 'absolute';
- container.top = 0;
- container.left = 0;
+ container = document.createElement('div')
+ container.id = 'container'
+ container.style.display = 'none'
+ container.style.position = 'absolute'
+ container.top = 0
+ container.left = 0
}
- body.appendChild(container);
+ body.appendChild(container)
container.innerHTML = ['',
'<ul>',
'<li class="first">1</li>',
@@ -27,67 +30,71 @@ describe('insertion.js', function(){
'<option>1</option>',
'<option selected="selected">2</option>',
'</select>'
- ].join('');
+ ].join('')
})
function $E(tag, id){
- var e = document.createElement(tag);
- e.id = id;
- return $(e);
+ var e = document.createElement(tag)
+ e.id = id
+ return $(e)
}
describe('implements standard w3c base methods', function(){
it('implements appendChild', function(){
- var ul = $(document.getElementById('container').firstChild);
- ul.appendChild($E('li', 'insertedLI'));
- var found = false;
- var index = 0;
+ var ul = $(document.getElementById('container').firstChild)
+ ul.appendChild($E('li', 'insertedLI'))
+ var found = false
+ var index = 0
$(document.getElementById('container').firstChild.childNodes).handle(function(element, i){
if (element.id == 'insertedLI'){
- found = true;
- index = i;
+ found = true
+ index = i
}
})
- expect(found).to.be.ok();
- expect(index).to.be(3);
+ expect(found).to.be.ok()
+ expect(index).to.be(3)
})
it('implements insertBefore', function(){
- var ul = $(document.getElementById('container').firstChild);
- var ins = $E('li', 'insertedLI');
- ul.appendChild(ins);
- var found = false;
- var index = 0;
- var bef = $E('li', 'beforeLI');
- ul.insertBefore(bef, ins);
- var found = false;
- var index = 0;
+ var ul = $(document.getElementById('container').firstChild),
+ ins = $E('li', 'insertedLI')
+
+ ul.appendChild(ins)
+
+ var found = false,
+ index = 0,
+ bef = $E('li', 'beforeLI')
+
+ ul.insertBefore(bef, ins)
+
$(document.getElementById('container').firstChild.childNodes).handle(function(element, i){
if (element.id == 'beforeLI'){
- found = true;
- index = i;
+ found = true
+ index = i
}
})
- expect(found).to.be.ok();
- expect(index).to.be(3);
+
+ expect(found).to.be.ok()
+ expect(index).to.be(3)
})
it('implements removeChild', function(){
- var ul = $(document.getElementById('container').firstChild);
- var lis = $(document.getElementById('container').firstChild.childNodes);
- expect(lis.length).to.be(3);
- ul.removeChild(lis[0]);
- lis = $(document.getElementById('container').firstChild.childNodes);
- expect(lis.length).to.be(2);
+ var ul = $(document.getElementById('container').firstChild)
+ var lis = $(document.getElementById('container').firstChild.childNodes)
+ expect(lis.length).to.be(3)
+ ul.removeChild(lis[0])
+ lis = $(document.getElementById('container').firstChild.childNodes)
+ expect(lis.length).to.be(2)
})
it('implements replaceChild', function(){
- var ul = $(document.getElementById('container').firstChild);
- var lis = $(document.getElementById('container').firstChild.childNodes);
- ul.replaceChild($E('li', 'replaced'), lis[0]);
- lis = $(document.getElementById('container').firstChild.childNodes);
- expect(lis[0].id == 'replaced').to.be.ok();
+ var ul = $(document.getElementById('container').firstChild)
+ var lis = $(document.getElementById('container').firstChild.childNodes)
+ ul.replaceChild($E('li', 'replaced'), lis[0])
+ lis = $(document.getElementById('container').firstChild.childNodes)
+
+ expect(lis[0].id).to.be('replaced')
})
})
@@ -97,45 +104,48 @@ describe('insertion.js', function(){
describe('before', function(){
it('should insert the current Nodes before the one passed', function(){
- var ul = $(document.getElementById('container').firstChild);
- var element = $E('div', 'divFirst');
- element.before(ul);
- expect($(document.getElementById('container').firstChild) == element).to.be.ok();
+ var ul = $(document.getElementById('container').firstChild)
+ var element = $E('div', 'divFirst')
+ element.before(ul)
+ expect($(document.getElementById('container').firstChild) == element).to.be.ok()
})
})
describe('after', function(){
it('should insert the current Nodes after the one passed', function(){
- var ul = $(document.getElementById('container').firstChild);
- var element = $E('li', 'placeholder');
- element.after(ul[0].firstChild);
- expect(ul[0].childNodes[1].id == 'placeholder').to.be.ok();
- var element2 = $E('li', 'placeholder2');
- element2.after(document.getElementById('third'));
- expect(ul[0].childNodes.length == 5).to.be.ok();
- expect(ul[0].childNodes[4].id == 'placeholder2').to.be.ok();
+ var ul = $(document.getElementById('container').firstChild)
+ var element = $E('li', 'placeholder')
+ element.after(ul[0].firstChild)
+
+ expect(ul[0].childNodes[1].id).to.be('placeholder')
+
+ var element2 = $E('li', 'placeholder2')
+ element2.after(document.getElementById('third'))
+
+ expect(ul[0].childNodes.length).to.be(5)
+ expect(ul[0].childNodes[4].id).to.be('placeholder2')
})
})
describe('bottom', function(){
it('should insert the current Nodes at the bottom of the one passed', function(){
- var ul = $(document.getElementById('container').firstChild);
- $E('li', 'placeholder').bottom(ul);
- expect(ul[0].childNodes[3].id == 'placeholder').to.be.ok();
+ var ul = $(document.getElementById('container').firstChild)
+ $E('li', 'placeholder').bottom(ul)
+ expect(ul[0].childNodes[3].id).to.be('placeholder')
})
})
describe('top', function(){
it('should insert the current Nodes at the top of the one passed', function(){
- var ul = $(document.getElementById('container').firstChild);
- $E('li', 'placeholder').top(ul);
- expect(ul[0].firstChild.id == 'placeholder').to.be.ok();
+ var ul = $(document.getElementById('container').firstChild)
+ $E('li', 'placeholder').top(ul)
+ expect(ul[0].firstChild.id).to.be('placeholder')
})
})
@@ -145,24 +155,24 @@ describe('insertion.js', function(){
describe('implements insert, remove, replace', function(){
it('should alias bottom as insert', function(){
- var ul = $(document.getElementById('container').firstChild);
- $E('li', 'placeholder').insert(ul);
- expect(ul[0].childNodes[3].id == 'placeholder').to.be.ok();
+ var ul = $(document.getElementById('container').firstChild)
+ $E('li', 'placeholder').insert(ul)
+ expect(ul[0].childNodes[3].id).to.be('placeholder')
})
it('should remove the current node', function(){
- var ul = $(document.getElementById('container').firstChild);
- var element = $E('li', 'placeholder');
- element.after(ul[0].firstChild);
- $(ul[0].firstChild).remove();
- expect(ul[0].firstChild.id == 'placeholder').to.be.ok();
+ var ul = $(document.getElementById('container').firstChild)
+ var element = $E('li', 'placeholder')
+ element.after(ul[0].firstChild)
+ $(ul[0].firstChild).remove()
+ expect(ul[0].firstChild.id).to.be('placeholder')
})
it('should swap the current node with the one passed', function(){
- var ul = $(document.getElementById('container').firstChild);
- var element = $E('li', 'placeholder');
- element.replace(ul[0].firstChild);
- expect(ul[0].firstChild.id == 'placeholder').to.be.ok();
+ var ul = $(document.getElementById('container').firstChild)
+ var element = $E('li', 'placeholder')
+ element.replace(ul[0].firstChild)
+ expect(ul[0].firstChild.id).to.be('placeholder')
})
})
View
5 test/list.html
@@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>nodes list tests</title>
- <link href="mocha.css" rel="stylesheet" type="text/css" media="screen"/>
+ <link href="mocha.css" rel="stylesheet" type="text/css" media="screen" />
<script src="mocha.js" type="text/javascript"></script>
<script>
@@ -20,8 +20,9 @@
</head>
<body>
-<a href="/">back</a>
+<a href="/">back</a>
<div id="mocha"></div>
+
</body>
</html>
View
59 test/list.js
@@ -1,20 +1,23 @@
"use strict";
+
var $ = require('../lib/list')
var expect = require('expect.js')
+
describe('list.js', function(){
+
// prepare the environment
beforeEach(function(){
- var body = document.getElementsByTagName('body')[0];
- var container = document.getElementById('container');
+ var body = document.getElementsByTagName('body')[0]
+ var container = document.getElementById('container')
if (!container){
- container = document.createElement('div');
- container.id = 'container';
- container.style.display = 'none';
- container.style.position = 'absolute';
- container.top = 0;
- container.left = 0;
+ container = document.createElement('div')
+ container.id = 'container'
+ container.style.display = 'none'
+ container.style.position = 'absolute'
+ container.top = 0
+ container.left = 0
}
- body.appendChild(container);
+ body.appendChild(container)
container.innerHTML = ['',
'<ul>',
'<li class="first">1</li>',
@@ -27,55 +30,55 @@ describe('list.js', function(){
'<option>1</option>',
'<option selected="selected">2</option>',
'</select>'
- ].join('');
+ ].join('')
})
describe('$ should implement es5 list prototypes', function(){
it('implement forEach', function(){
- var ul = $(document.getElementById('container').firstChild);
- var lis = $(ul[0].childNodes);
+ var ul = $(document.getElementById('container').firstChild)
+ var lis = $(ul[0].childNodes)
lis.forEach(function(el, i, self){
- expect(el.innerHTML).to.be('' + (i + 1));
+ expect(el.innerHTML).to.be('' + (i + 1))
})
})
it('implement map', function(){
- var lis = $(document.getElementById('container').firstChild.childNodes);
+ var lis = $(document.getElementById('container').firstChild.childNodes)
var maps = lis.map(function(el){
return el.innerHTML
- });
- expect(maps[0]).to.be('1');
- expect(maps[1]).to.be('2');
- expect(maps[2]).to.be('3');
+ })
+ expect(maps[0]).to.be('1')
+ expect(maps[1]).to.be('2')
+ expect(maps[2]).to.be('3')
})
it('implement filter', function(){
- var lis = $(document.getElementById('container').firstChild.childNodes);
+ var lis = $(document.getElementById('container').firstChild.childNodes)
var maps = lis.filter(function(el){
- return el.innerHTML - 0 < 3;
- });
- expect(maps.length).to.be(2);
+ return el.innerHTML - 0 < 3
+ })
+ expect(maps.length).to.be(2)
})
it('implement every', function(){
- var lis = $(document.getElementById('container').firstChild.childNodes);
+ var lis = $(document.getElementById('container').firstChild.childNodes)
expect(lis.every(function(el){
return el.tagName.toLowerCase() == 'li'
- })).to.be.ok();
+ })).to.be.ok()
expect(lis.every(function(el){
return el.innerHTML == '1'
- })).to.be(false);
+ })).to.be(false)
})
it('implement some', function(){
- var lis = $(document.getElementById('container').firstChild.childNodes);
+ var lis = $(document.getElementById('container').firstChild.childNodes)
expect(lis.some(function(el){
return el.tagName == 'p'
- })).to.be(false);
+ })).to.be(false)
expect(lis.some(function(el){
return el.innerHTML == '1'
- })).to.be.ok();
+ })).to.be.ok()
})
})
View
5 test/nodes.html
@@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>Nodes base tests</title>
- <link href="mocha.css" rel="stylesheet" type="text/css" media="screen"/>
+ <link href="mocha.css" rel="stylesheet" type="text/css" media="screen" />
<script src="mocha.js" type="text/javascript"></script>
<script>
@@ -20,8 +20,9 @@
</head>
<body>
-<a href="/">back</a>
+<a href="/">back</a>
<div id="mocha"></div>
+
</body>
</html>
View
136 test/nodes.js
@@ -1,20 +1,23 @@
"use strict";
+
var $ = require('../lib/nodes')
var expect = require('expect.js')
+
describe('nodes.js', function(){
+
// prepare the environment
beforeEach(function(){
- var body = document.getElementsByTagName('body')[0];
- var container = document.getElementById('container');
+ var body = document.getElementsByTagName('body')[0]
+ var container = document.getElementById('container')
if (!container){
- container = document.createElement('div');
- container.id = 'container';
- container.style.display = 'none';
- container.style.position = 'absolute';
- container.top = 0;
- container.left = 0;
+ container = document.createElement('div')
+ container.id = 'container'
+ container.style.display = 'none'
+ container.style.position = 'absolute'
+ container.top = 0
+ container.left = 0
}
- body.appendChild(container);
+ body.appendChild(container)
container.innerHTML = ['',
'<ul>',
'<li class="first">1</li>',
@@ -27,109 +30,112 @@ describe('nodes.js', function(){
'<option>1</option>',
'<option selected="selected">2</option>',
'</select>'
- ].join('');
- });
+ ].join('')
+ })
it('should receive null and return null', function(){
- expect($(null)).to.be(null);
+ expect($(null)).to.be(null)
})
it('should return an instance of Nodes that is an instance of $', function(){
//Nodes is not accessible but it inherits from $, so we test that
- var isInstance = $(document.documentElement) instanceof $;
- expect(isInstance).to.be.ok();
+ var isInstance = $(document.documentElement) instanceof $
+ expect(isInstance).to.be.ok()
})
it('should return the very instance of Nodes if a Nodes instance is passed', function(){
- var html = $(document.documentElement);
- var isTheSame = $(html) === html;
- expect(isTheSame).to.be.ok();
+ var html = $(document.documentElement)
+ var isTheSame = $(html) === html
+ expect(isTheSame).to.be.ok()
})
it('should correctly handle Array', function(){
- expect($([])).to.be(null);
- var res = $([document.documentElement]);
- expect(res.length).to.be(1);
- expect(res instanceof $).to.be.ok();
- expect(res[0] instanceof $).to.be(false);
- var res2 = $([document.documentElement, document.getElementById('third')]);
- expect(res2.length).to.be(2);
+ expect($([])).to.be(null)
+ var res = $([document.documentElement])
+ expect(res.length).to.be(1)
+ expect(res instanceof $).to.be.ok()
+ expect(res[0] instanceof $).to.be(false)
+ var res2 = $([document.documentElement, document.getElementById('third')])
+ expect(res2.length).to.be(2)
})
describe('expose a handle method that ', function(){
var setRel = function(element, index){
- element.setAttribute('rel', 'handled' + index);
- return element;
- };
+ element.setAttribute('rel', 'handled' + index)
+ return element
+ }
it('is a sort of Array.map', function(){
- var lis = $(document.getElementById('container').getElementsByTagName('li'));
- expect(lis.length).to.be(3);
- var res = lis.handle(setRel);
- expect(res[0].getAttribute('rel')).to.be('handled0');
- expect(res[1].getAttribute('rel')).to.be('handled1');
+ var lis = $(document.getElementById('container').getElementsByTagName('li'))
+ expect(lis.length).to.be(3)
+ var res = lis.handle(setRel)
+ expect(res[0].getAttribute('rel')).to.be('handled0')
+ expect(res[1].getAttribute('rel')).to.be('handled1')
})
it('can be used as Array.some', function(){
var someHasRelHandled1 = function(element, index, buffer){
if (element.getAttribute('rel') == 'handled1'){
- buffer.push(true);
- return true;
+ buffer.push(true)
+ return true
}
- };
- var lis = $(document.getElementById('container').getElementsByTagName('li'));
- lis.handle(setRel);
- var res = lis.handle(someHasRelHandled1);
- expect(res.length).to.be(1);
- expect(res[0]).to.be.ok();
- var options = $(document.getElementById('container').getElementsByTagName('option'));
- var res = options.handle(someHasRelHandled1);
- expect(res.length).to.be(0);
+ }
+ var lis = $(document.getElementById('container').getElementsByTagName('li'))
+ var res
+ lis.handle(setRel)
+ res = lis.handle(someHasRelHandled1)
+
+ expect(res.length).to.be(1)
+ expect(res[0]).to.be.ok()
+
+ var options = $(document.getElementById('container').getElementsByTagName('option'))
+ res = options.handle(someHasRelHandled1)
+ expect(res.length).to.be(0)
})
it('can be used as Array.every', function(){
- var lis = $(document.getElementById('container').getElementsByTagName('li'));
- lis.handle(setRel);
+ var lis = $(document.getElementById('container').getElementsByTagName('li'))
+ lis.handle(setRel)
var everyHasRel = function(element){
- if (null === element.getAttribute('rel')) return false;
- return this;
- };
- var res = lis.handle(everyHasRel);
- expect(res.length).to.be(lis.length);
- var options = $(document.getElementById('container').getElementsByTagName('option'));
- var res = options.handle(everyHasRel);
- expect(res.length).to.not.be(options.length);
+ if (null === element.getAttribute('rel')) return false
+ return this
+ }
+ var res = lis.handle(everyHasRel)
+ expect(res.length).to.be(lis.length)
+ var options = $(document.getElementById('container').getElementsByTagName('option'))
+ res = options.handle(everyHasRel)
+ expect(res.length).to.not.be(options.length)
})
it('expose a use method, to allow custom selector', function(){
- var html = $(document.documentElement);
+ var html = $(document.documentElement)
$.use({
prototype: {
},
search: function(n, ctx, self){
- self[self.length++] = document.documentElement;
+ self[self.length++] = document.documentElement
}
- });
- expect($('^_^') == html).to.be.ok();
+ })
+ expect($('^_^') == html).to.be.ok()
})
it('expose a use method, to allow custom sorter', function(){
- var lis = $(document.getElementById('container').getElementsByTagName('li'));
+ var lis = $(document.getElementById('container').getElementsByTagName('li'))
$.use({
prototype: {},
sort: function(self){
//swap self[0] with self[1]
- var tmp = self[0];
- self[0] = self[1];
- self[1] = tmp;
+ var tmp = self[0]
+ self[0] = self[1]
+ self[1] = tmp
}
})
- var lis2 = $(document.getElementById('container').getElementsByTagName('li'));
- expect(lis2[0] == lis[1]).to.be.ok();
- expect(lis2[1] == lis[0]).to.be.ok();
- expect(lis2[2] == lis[2]).to.be.ok();
+ var lis2 = $(document.getElementById('container').getElementsByTagName('li'))
+ expect(lis2[0] == lis[1]).to.be.ok()
+ expect(lis2[1] == lis[0]).to.be.ok()
+ expect(lis2[2] == lis[2]).to.be.ok()
})
})

0 comments on commit ff55824

Please sign in to comment.