Skip to content

Commit

Permalink
Remove all the semicolons!
Browse files Browse the repository at this point in the history
- change some expect(a == b).to.be.ok() into expect(a).to.be(b)
- fix some double defined vars
  • Loading branch information
Arian committed May 16, 2012
1 parent d73f5c7 commit ff55824
Show file tree
Hide file tree
Showing 12 changed files with 335 additions and 307 deletions.
4 changes: 4 additions & 0 deletions Makefile
Expand Up @@ -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'

5 changes: 3 additions & 2 deletions test/attributes.html
Expand Up @@ -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>
Expand All @@ -20,8 +20,9 @@

</head>
<body>
<a href="/">back</a>

<a href="/">back</a>
<div id="mocha"></div>

</body>
</html>
233 changes: 115 additions & 118 deletions 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>',
Expand All @@ -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
}
})
})
Expand All @@ -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)
})

})
Expand All @@ -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")
})

})
Expand Down

0 comments on commit ff55824

Please sign in to comment.