Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

removed some extra vars and fixed jslint errors

  • Loading branch information...
commit 724c295dc6d21ac31c5658013c3a379ab8b384af 1 parent 598e09e
Matthew Mueller authored
View
44 test/api.manipulation.js
@@ -1,8 +1,6 @@
-var expect = require('expect.js');
-
-var $ = require('../');
-var fruits = require('./fixtures').fruits;
-
+var expect = require('expect.js'),
+ $ = require('../'),
+ fruits = require('./fixtures').fruits;
describe('$(...)', function() {
@@ -15,14 +13,14 @@ describe('$(...)', function() {
it('(html) : should add element as last child', function() {
var $fruits = $(fruits);
$('#fruits', $fruits).append('<li class="plum">Plum</li>');
- expect($('#fruits', $fruits).children(3).hasClass('plum')).to.be.ok;
+ expect($('#fruits', $fruits).children(3).hasClass('plum')).to.be.ok();
});
it('($(...)) : should add element as last child', function() {
var $fruits = $(fruits);
var $plum = $('<li class="plum">Plum</li>');
$('#fruits', $fruits).append($plum);
- expect($('#fruits', $fruits).children(3).hasClass('plum')).to.be.ok;
+ expect($('#fruits', $fruits).children(3).hasClass('plum')).to.be.ok();
});
it('($(...), html) : should add multiple elements as last children', function() {
@@ -30,8 +28,8 @@ describe('$(...)', function() {
var $plum = $('<li class="plum">Plum</li>');
var grape = '<li class="grape">Grape</li>';
$('#fruits', $fruits).append($plum, grape);
- expect($('#fruits', $fruits).children(3).hasClass('plum')).to.be.ok;
- expect($('#fruits', $fruits).children(4).hasClass('grape')).to.be.ok;
+ expect($('#fruits', $fruits).children(3).hasClass('plum')).to.be.ok();
+ expect($('#fruits', $fruits).children(4).hasClass('grape')).to.be.ok();
});
it('(fn) : should add returned element as last child');
@@ -42,7 +40,7 @@ describe('$(...)', function() {
.children()
.children()
.parent();
- expect(obj).to.be.ok;
+ expect(obj).to.be.ok();
});
});
@@ -56,14 +54,14 @@ describe('$(...)', function() {
it('(html) : should add element as first child', function() {
var $fruits = $(fruits);
$('#fruits', $fruits).prepend('<li class="plum">Plum</li>');
- expect($('#fruits', $fruits).children(0).hasClass('plum')).to.be.ok;
+ expect($('#fruits', $fruits).children(0).hasClass('plum')).to.be.ok();
});
it('($(...)) : should add element as first child', function() {
var $fruits = $(fruits);
var $plum = $('<li class="plum">Plum</li>');
$('#fruits', $fruits).prepend($plum);
- expect($('#fruits', $fruits).children(0).hasClass('plum')).to.be.ok;
+ expect($('#fruits', $fruits).children(0).hasClass('plum')).to.be.ok();
});
it('(html, $(...), html) : should add multiple elements as first children', function() {
@@ -71,8 +69,8 @@ describe('$(...)', function() {
var $plum = $('<li class="plum">Plum</li>');
var grape = '<li class="grape">Grape</li>';
$('#fruits', $fruits).prepend($plum, grape);
- expect($('#fruits', $fruits).children(0).hasClass('plum')).to.be.ok;
- expect($('#fruits', $fruits).children(1).hasClass('grape')).to.be.ok;
+ expect($('#fruits', $fruits).children(0).hasClass('plum')).to.be.ok();
+ expect($('#fruits', $fruits).children(1).hasClass('grape')).to.be.ok();
});
it('(fn) : should add returned element as first child');
@@ -89,14 +87,14 @@ describe('$(...)', function() {
var $fruits = $(fruits);
var grape = '<li class="grape">Grape</li>';
$('.apple', $fruits).after(grape);
- expect($('.apple', $fruits).next().hasClass('grape')).to.be.ok;
+ expect($('.apple', $fruits).next().hasClass('grape')).to.be.ok();
});
it('($(...)) : should add element as next sibling', function() {
var $fruits = $(fruits);
var $plum = $('<li class="plum">Plum</li>');
$('.apple', $fruits).after($plum);
- expect($('.apple', $fruits).next().hasClass('plum')).to.be.ok;
+ expect($('.apple', $fruits).next().hasClass('plum')).to.be.ok();
});
it('($(...), html) : should add multiple elements as next siblings', function() {
@@ -104,8 +102,8 @@ describe('$(...)', function() {
var $plum = $('<li class="plum">Plum</li>');
var grape = '<li class="grape">Grape</li>';
$('.apple', $fruits).after($plum, grape);
- expect($('.apple', $fruits).next().hasClass('plum')).to.be.ok;
- expect($('.plum', $fruits).next().hasClass('grape')).to.be.ok;
+ expect($('.apple', $fruits).next().hasClass('plum')).to.be.ok();
+ expect($('.plum', $fruits).next().hasClass('grape')).to.be.ok();
});
it('(fn) : should add returned element as next sibling');
@@ -122,14 +120,14 @@ describe('$(...)', function() {
var $fruits = $(fruits);
var grape = '<li class="grape">Grape</li>';
$('.apple', $fruits).before(grape);
- expect($('.apple', $fruits).prev().hasClass('grape')).to.be.ok;
+ expect($('.apple', $fruits).prev().hasClass('grape')).to.be.ok();
});
it('($(...)) : should add element as previous sibling', function() {
var $fruits = $(fruits);
var $plum = $('<li class="plum">Plum</li>');
$('.apple', $fruits).before($plum);
- expect($('.apple', $fruits).prev().hasClass('plum')).to.be.ok;
+ expect($('.apple', $fruits).prev().hasClass('plum')).to.be.ok();
});
it('($(...), html) : should add multiple elements as previous siblings', function() {
@@ -137,8 +135,8 @@ describe('$(...)', function() {
var $plum = $('<li class="plum">Plum</li>');
var grape = '<li class="grape">Grape</li>';
$('.apple', $fruits).before($plum, grape);
- expect($('.apple', $fruits).prev().hasClass('grape')).to.be.ok;
- expect($('.grape', $fruits).prev().hasClass('plum')).to.be.ok;
+ expect($('.apple', $fruits).prev().hasClass('grape')).to.be.ok();
+ expect($('.grape', $fruits).prev().hasClass('plum')).to.be.ok();
});
it('(fn) : should add returned element as previous sibling');
@@ -167,7 +165,7 @@ describe('$(...)', function() {
var $fruits = $(fruits);
var plum = $('<li class="plum">Plum</li>');
$('.pear', $fruits).replaceWith(plum);
- expect($('.orange', $fruits).next().hasClass('plum')).to.be.ok;
+ expect($('.orange', $fruits).next().hasClass('plum')).to.be.ok();
expect($('.orange', $fruits).next().html()).to.equal('Plum');
});
View
13 test/api.traversing.js
@@ -1,7 +1,6 @@
-var expect = require('expect.js');
-
-var $ = require('../');
-var fruits = require('./fixtures').fruits;
+var expect = require('expect.js'),
+ $ = require('../'),
+ fruits = require('./fixtures').fruits;
describe('$(...)', function() {
@@ -39,7 +38,7 @@ describe('$(...)', function() {
});
it('(selector) : should return children matching selector', function() {
- expect($('ul', fruits).children('.orange').hasClass('orange')).to.be.ok;
+ expect($('ul', fruits).children('.orange').hasClass('orange')).to.be.ok();
});
it('(invalid selector) : should return empty', function() {
@@ -53,7 +52,7 @@ describe('$(...)', function() {
describe('.next', function() {
it('() : should return next element', function() {
- expect($('.orange', fruits).next().hasClass('pear')).to.be.ok;
+ expect($('.orange', fruits).next().hasClass('pear')).to.be.ok();
});
it('(no next) : should return null (?)');
@@ -63,7 +62,7 @@ describe('$(...)', function() {
describe('.prev', function() {
it('() : should return previous element', function() {
- expect($('.orange', fruits).prev().hasClass('apple')).to.be.ok;
+ expect($('.orange', fruits).prev().hasClass('apple')).to.be.ok();
});
it('(no prev) : should return null (?)');
View
5 test/api.utils.js
@@ -1,6 +1,5 @@
-var expect = require('expect.js');
-
-var $ = require('../');
+var expect = require('expect.js'),
+ $ = require('../');
describe('$', function() {
View
33 test/cheerio.js
@@ -1,51 +1,50 @@
-var expect = require('expect.js');
-var _ = require('underscore');
+var expect = require('expect.js'),
+ _ = require('underscore'),
+ $ = require('../'),
+ fruits = require('./fixtures').fruits;
-var $ = require('../');
-var fruits = require('./fixtures').fruits;
-
-
-var script = '<script src="script.js" type="text/javascript"></script>';
-var multiclass = '<p><a class="btn primary" href="#">Save</a></p>';
+// HTML
+var script = '<script src="script.js" type="text/javascript"></script>',
+ multiclass = '<p><a class="btn primary" href="#">Save</a></p>';
describe('cheerio', function() {
it('should get the version', function() {
- expect(/\d\.\d\.\d/.test($.version)).to.be.ok;
+ expect(/\d\.\d\.\d/.test($.version)).to.be.ok();
});
it('$(null) should return be empty', function() {
- expect($(null)).to.be.empty;
+ expect($(null)).to.be.empty();
});
it('$(undefined) should be empty', function() {
- expect($(undefined)).to.be.empty;
+ expect($(undefined)).to.be.empty();
});
it('$(null) should be empty', function() {
- expect($('')).to.be.empty;
+ expect($('')).to.be.empty();
});
it('$(selector) with no context or root should be empty', function() {
- expect($('.h2')).to.be.empty;
- expect($('#fruits')).to.be.empty;
+ expect($('.h2')).to.be.empty();
+ expect($('#fruits')).to.be.empty();
});
it('should be able to create html without a root or context', function() {
var $h2 = $('<h2>');
- expect($h2).to.not.be.empty;
+ expect($h2).to.not.be.empty();
expect($h2).to.have.length(1);
expect($h2[0].name).to.equal('h2');
});
it('should be able to create complicated html', function() {
var $script = $(script);
- expect($script).to.not.be.empty;
+ expect($script).to.not.be.empty();
expect($script).to.have.length(1);
expect($script[0].attribs.src).to.equal('script.js');
expect($script[0].attribs.type).to.equal('text/javascript');
- expect($script[0].children).to.be.empty;
+ expect($script[0].children).to.be.empty();
});
var testAppleSelect = function($apple) {
View
18 test/fixtures.js
@@ -1,11 +1,7 @@
-module.exports = {
-
- fruits: [
- '<ul id="fruits">',
- '<li class="apple">Apple</li>',
- '<li class="orange">Orange</li>',
- '<li class="pear">Pear</li>',
- '</ul>'
- ].join('')
-
-};
+exports.fruits = [
+ '<ul id="fruits">',
+ '<li class="apple">Apple</li>',
+ '<li class="orange">Orange</li>',
+ '<li class="pear">Pear</li>',
+ '</ul>'
+].join('');
View
3  test/mocha.opts
@@ -1,3 +1,2 @@
--reporter list
---growl
---compilers coffee:coffee-script
+--growl
View
71 test/parse.js
@@ -1,6 +1,5 @@
-var expect = require('expect.js');
-
-var parse = require('../').parse;
+var expect = require('expect.js'),
+ parse = require('../').parse;
// Tags
@@ -46,14 +45,15 @@ describe('parse', function() {
var tag = parse['eval'](basic)[0];
expect(tag.type).to.equal('tag');
expect(tag.name).to.equal('html');
- expect(tag.children).to.be.empty;
+ expect(tag.children).to.be.empty();
});
it('should handle sibling tags: ' + siblings, function() {
- var dom = parse['eval'](siblings);
+ var dom = parse['eval'](siblings),
+ h2 = dom[0],
+ p = dom[1];
+
expect(dom).to.have.length(2);
- var h2 = dom[0];
- var p = dom[1];
expect(h2.name).to.equal('h2');
expect(p.name).to.equal('p');
});
@@ -62,21 +62,21 @@ describe('parse', function() {
var tag = parse['eval'](single)[0];
expect(tag.type).to.equal('tag');
expect(tag.name).to.equal('br');
- expect(tag.children).to.be.empty;
+ expect(tag.children).to.be.empty();
});
it('should handle malformatted single tags: ' + singleWrong, function() {
var tag = parse['eval'](singleWrong)[0];
expect(tag.type).to.equal('tag');
expect(tag.name).to.equal('br');
- expect(tag.children).to.be.empty;
+ expect(tag.children).to.be.empty();
});
it('should handle tags with children: ' + children, function() {
var tag = parse['eval'](children)[0];
expect(tag.type).to.equal('tag');
expect(tag.name).to.equal('html');
- expect(tag.children).to.be.ok;
+ expect(tag.children).to.be.ok();
expect(tag.children).to.have.length(1);
});
@@ -88,14 +88,14 @@ describe('parse', function() {
it('should handle tags with attributes: ' + attributes, function() {
var attrs = parse['eval'](attributes)[0].attribs;
- expect(attrs).to.be.ok;
+ expect(attrs).to.be.ok();
expect(attrs.src).to.equal('hello.png');
expect(attrs.alt).to.equal('man waving');
});
it('should handle value-less attributes: ' + noValueAttribute, function() {
var attrs = parse['eval'](noValueAttribute)[0].attribs;
- expect(attrs).to.be.ok;
+ expect(attrs).to.be.ok();
expect(attrs.disabled).to.equal('');
});
@@ -162,8 +162,8 @@ describe('parse', function() {
expect(tag.prev).to.be(null);
// Should exist but be empty
- expect(tag.children).to.be.empty;
- expect(tag.attribs).to.be.ok;
+ expect(tag.children).to.be.empty();
+ expect(tag.attribs).to.be.ok();
});
it('should should fill in empty attributes for scripts: ' + scriptEmpty, function() {
@@ -175,8 +175,8 @@ describe('parse', function() {
expect(script.prev).to.be(null);
// Should exist but be empty
- expect(script.children).to.be.empty;
- expect(script.attribs).to.be.ok;
+ expect(script.children).to.be.empty();
+ expect(script.attribs).to.be.ok();
});
it('should should fill in empty attributes for styles: ' + styleEmpty, function() {
@@ -188,14 +188,14 @@ describe('parse', function() {
expect(style.prev).to.be(null);
// Should exist but be empty
- expect(style.children).to.be.empty;
- expect(style.attribs).to.be.ok;
+ expect(style.children).to.be.empty();
+ expect(style.attribs).to.be.ok();
});
it('should have next and prev siblings: ' + siblings, function() {
- var dom = create(siblings);
- var h2 = dom[0];
- var p = dom[1];
+ var dom = create(siblings),
+ h2 = dom[0],
+ p = dom[1];
// No parents
expect(h2.parent).to.be(null);
@@ -206,21 +206,21 @@ describe('parse', function() {
expect(p.prev.name).to.equal('h2');
// Should exist but be empty
- expect(h2.children).to.be.empty;
- expect(h2.attribs).to.be.ok;
- expect(p.children).to.be.empty;
- expect(p.attribs).to.be.ok;
+ expect(h2.children).to.be.empty();
+ expect(h2.attribs).to.be.ok();
+ expect(p.children).to.be.empty();
+ expect(p.attribs).to.be.ok();
});
it('should connect child with parent: ' + children, function() {
- var html = create(children)[0];
+ var html = create(children)[0],
+ br = html.children[0];
// html has 1 child and it's <br>
expect(html.children).to.have.length(1);
expect(html.children[0].name).to.equal('br');
// br's parent is html
- var br = html.children[0];
expect(br.parent.name).to.equal('html');
});
@@ -233,8 +233,8 @@ describe('parse', function() {
expect(elem.prev).to.be(null);
// Should not exist at all
- expect(elem.children).to.not.be.ok;
- expect(elem.attribs).to.not.be.ok;
+ expect(elem.children).to.not.be.ok();
+ expect(elem.attribs).to.not.be.ok();
});
it('should fill in some empty attributes for text: ' + text, function() {
@@ -246,8 +246,8 @@ describe('parse', function() {
expect(text.prev).to.be(null);
// Should not exist at all
- expect(text.children).to.not.be.ok;
- expect(text.attribs).to.not.be.ok;
+ expect(text.children).to.not.be.ok();
+ expect(text.attribs).to.not.be.ok();
});
it('should fill in some empty attributes for directives: ' + directive, function() {
@@ -259,15 +259,16 @@ describe('parse', function() {
expect(elem.prev).to.be(null);
// Should not exist at all
- expect(elem.children).to.not.be.ok;
- expect(elem.attribs).to.not.be.ok;
+ expect(elem.children).to.not.be.ok();
+ expect(elem.attribs).to.not.be.ok();
});
});
describe('.parse', function() {
- var rootTest = function(root) {
+ // root test utility
+ function rootTest(root) {
expect(root.name).to.equal('root');
// Should exist but be null
@@ -277,7 +278,7 @@ describe('parse', function() {
var child = root.children[0];
expect(child.parent).to.equal(root);
- };
+ }
it('should add root to: ' + basic, function() {
var root = parse(basic);
View
26 test/render.js
@@ -1,26 +1,10 @@
-var expect = require('expect.js');
-
-var cheerio = require('../');
-var parse = cheerio.parse;
-var render = cheerio.render;
-
-
-// TODO: Write tests for render
-
-// Tags
-
-// Text
-
-// Directives
-
-// Style
-
-// Script
-
-// Comments
+var expect = require('expect.js'),
+ cheerio = require('../'),
+ parse = cheerio.parse,
+ render = cheerio.render;
var html = function(str, options) {
- if (options == null) options = {};
+ if (options === null) options = {};
@davidchambers Owner
> coffee -bep '(str, options = {}) ->'
(function(str, options) {
  if (options == null) {
    options = {};
  }
});

If options is meant to be an optional argument, we need to use == to match null or undefined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
var dom = parse(str, options);
return render(dom);
};

2 comments on commit 724c295

@davidchambers

I was going to look at exactly what expect(expression).to.be.ok does. It certainly looks as though it should be a method call (and Vim kept telling me so), but I wondered whether it's a magical "getter". In the end I just trusted the CoffeeScript tests, but it turns out we were never actually invoking the ok method. >.<

@matthewmueller

Ohhh right good catch on options, I tend to go with options = options || {}.. let me fix that now.

And yah, haha, I noticed that after the 2nd pass - that was my fault when I swapped out should.js for expect.js :-[

Please sign in to comment.
Something went wrong with that request. Please try again.