From 0875471ffb2c123bb235cf52763b91c2fdac7676 Mon Sep 17 00:00:00 2001 From: Ivan Miric Date: Mon, 3 Mar 2014 18:12:17 +0100 Subject: [PATCH 1/5] Refactor tests into mocha/chai --- component.json | 5 +++- test.html | 30 ----------------------- test/index.js | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ test/test.html | 21 ++++++++++++++++ 4 files changed, 91 insertions(+), 31 deletions(-) delete mode 100644 test.html create mode 100644 test/index.js create mode 100644 test/test.html diff --git a/component.json b/component.json index 9b4bb03..a216a97 100644 --- a/component.json +++ b/component.json @@ -7,7 +7,10 @@ "dependencies": { "component/classes" : "*" }, - "development": {}, + "development": { + "visionmedia/mocha": "*", + "chaijs/chai": "*" + }, "license": "MIT", "scripts": [ "index.js" diff --git a/test.html b/test.html deleted file mode 100644 index 98bc7f0..0000000 --- a/test.html +++ /dev/null @@ -1,30 +0,0 @@ - - - helix component - - - -

helix component

- -
- Matt - - - about -
- - - - - diff --git a/test/index.js b/test/index.js new file mode 100644 index 0000000..2995122 --- /dev/null +++ b/test/index.js @@ -0,0 +1,66 @@ + +/** + * Module dependencies. + */ + +var helix = require('helix'), + should = require('chai').should(); + +describe('selector', function(){ + it('should throw error if missing', function(){ + // Work on a copy of the elements, to not modify for other tests + var $ = helix(document.querySelector('.person').cloneNode(true)); + (function() { $('.missing') }).should.throw(Error); + }) + + it('should select correct element', function(){ + var $ = helix(document.querySelector('.person').cloneNode(true)); + (function() { $('.name') }).should.not.throw(Error); + var el = $('.name').el; + el.should.have.property('nodeType').with.valueOf(1); + el.className.should.equal('name'); + }) +}) + +describe('contents', function(){ + it('should return inner text', function(){ + var $ = helix(document.querySelector('.person').cloneNode(true)); + $('.name').text().should.equal('Matt'); + }) + + it('should set inner text', function(){ + var $ = helix(document.querySelector('.person').cloneNode(true)); + $('.name').text('Harry'); + $('.name').text().should.equal('Harry'); + }) + + it('should return inner HTML', function(){ + var $ = helix(document.querySelector('.person').cloneNode(true)); + $('a').html().should.equal('about'); + }) + + it('should set inner HTML', function(){ + var $ = helix(document.querySelector('.person').cloneNode(true)); + $('a').html('lol'); + $('a').html().should.equal('lol'); + }) +}) + +describe('attributes', function(){ + it('should return existing attribute value', function(){ + var $ = helix(document.querySelector('.person').cloneNode(true)); + $('a').href().should.equal('/about'); + }) + + it('should change attribute value', function(){ + var $ = helix(document.querySelector('.person').cloneNode(true)); + $('a').href('/me'); + $('a').href().should.equal('/me'); + }) + + it('should add new attribute', function(){ + var $ = helix(document.querySelector('.person').cloneNode(true)); + $('.name').attr('data-type', 'first'); + $('.name').attr('data-type').should.equal('first'); + }) +}) diff --git a/test/test.html b/test/test.html new file mode 100644 index 0000000..1b673d2 --- /dev/null +++ b/test/test.html @@ -0,0 +1,21 @@ + + + helix component + + + + +
+ + + + + + From 8f8941d059617a2304536dfcaaff8d5ea8065c5e Mon Sep 17 00:00:00 2001 From: Ivan Miric Date: Mon, 3 Mar 2014 18:13:16 +0100 Subject: [PATCH 2/5] Add classes tests --- test/index.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/index.js b/test/index.js index 2995122..b95052b 100644 --- a/test/index.js +++ b/test/index.js @@ -64,3 +64,27 @@ describe('attributes', function(){ $('.name').attr('data-type').should.equal('first'); }) }) + +describe('classes', function(){ + it('should add a new class', function(){ + var $ = helix(document.querySelector('.person').cloneNode(true)); + $('a').addClass('link'); + $('a').classes.contains('link').should.equal(true); + }) + + it('should remove a class', function(){ + var $ = helix(document.querySelector('body').cloneNode(true)); + $('div').classes.contains('person').should.equal(true); + $('div').removeClass('person'); + $('div').classes.contains('person').should.equal(false); + }) + + it('should toggle a class', function(){ + var $ = helix(document.querySelector('body').cloneNode(true)); + $('div').classes.contains('person').should.equal(true); + $('div').toggle('person'); + $('div').classes.contains('person').should.equal(false); + $('div').toggle('person'); + $('div').classes.contains('person').should.equal(true); + }) +}) From 4d963569f046ab272f94da80aaf3cb7b5a4d7b42 Mon Sep 17 00:00:00 2001 From: Ivan Miric Date: Mon, 3 Mar 2014 18:20:10 +0100 Subject: [PATCH 3/5] Pass classes tests --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 84b8ff5..c3796f3 100644 --- a/index.js +++ b/index.js @@ -86,7 +86,7 @@ Helix.prototype.html = function(str) { */ Helix.prototype.addClass = function(cls) { - this.classes(this.el).add(cls); + this.classes.add(cls); return this; }; @@ -99,7 +99,7 @@ Helix.prototype.addClass = function(cls) { */ Helix.prototype.removeClass = function(cls) { - this.classes(this.el).remove(cls); + this.classes.remove(cls); return this; }; @@ -112,7 +112,7 @@ Helix.prototype.removeClass = function(cls) { */ Helix.prototype.toggle = function(cls) { - this.classes(this.el).toggle(cls); + this.classes.toggle(cls); return this; }; From 57a7a7a5ac04497d4ce03fff63057d4d2f627898 Mon Sep 17 00:00:00 2001 From: Ivan Miric Date: Mon, 3 Mar 2014 18:28:58 +0100 Subject: [PATCH 4/5] Added tests info to Readme --- Readme.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Readme.md b/Readme.md index cc3f7ee..13a8c2c 100644 --- a/Readme.md +++ b/Readme.md @@ -6,6 +6,11 @@ $ component install matthewmueller/helix +## Tests + + $ make clean && make + $ xdg-open test/test.html + ## API ### Helix(el) From de44cb2216eb5acdb0fd8d77fe432aa0985bc100 Mon Sep 17 00:00:00 2001 From: Ivan Miric Date: Tue, 4 Mar 2014 21:45:06 +0100 Subject: [PATCH 5/5] Proper structure and function names in tests --- test/index.js | 134 ++++++++++++++++++++++++++++---------------------- 1 file changed, 75 insertions(+), 59 deletions(-) diff --git a/test/index.js b/test/index.js index b95052b..972efee 100644 --- a/test/index.js +++ b/test/index.js @@ -6,85 +6,101 @@ var helix = require('helix'), should = require('chai').should(); -describe('selector', function(){ - it('should throw error if missing', function(){ - // Work on a copy of the elements, to not modify for other tests - var $ = helix(document.querySelector('.person').cloneNode(true)); - (function() { $('.missing') }).should.throw(Error); - }) +describe('Helix', function(){ + describe('Helix(selector)', function(){ + it('should throw an error if missing selector', function(){ + // Work on a copy of the elements, to not modify for other tests + var $ = helix(document.querySelector('.person').cloneNode(true)); + (function() { $('.missing') }).should.throw(Error); + }) - it('should select correct element', function(){ - var $ = helix(document.querySelector('.person').cloneNode(true)); - (function() { $('.name') }).should.not.throw(Error); - var el = $('.name').el; - el.should.have.property('nodeType').with.valueOf(1); - el.className.should.equal('name'); + it('should select the correct element', function(){ + var $ = helix(document.querySelector('.person').cloneNode(true)); + (function() { $('.name') }).should.not.throw(Error); + var el = $('.name').el; + el.should.have.property('nodeType').with.valueOf(1); + el.className.should.equal('name'); + }) }) -}) -describe('contents', function(){ - it('should return inner text', function(){ - var $ = helix(document.querySelector('.person').cloneNode(true)); - $('.name').text().should.equal('Matt'); + describe('#text()', function(){ + it('should return inner text', function(){ + var $ = helix(document.querySelector('.person').cloneNode(true)); + $('.name').text().should.equal('Matt'); + }) }) - it('should set inner text', function(){ - var $ = helix(document.querySelector('.person').cloneNode(true)); - $('.name').text('Harry'); - $('.name').text().should.equal('Harry'); + describe('#text(val)', function(){ + it('should set inner text', function(){ + var $ = helix(document.querySelector('.person').cloneNode(true)); + $('.name').text('Harry'); + $('.name').text().should.equal('Harry'); + }) }) - it('should return inner HTML', function(){ - var $ = helix(document.querySelector('.person').cloneNode(true)); - $('a').html().should.equal('about'); + describe('#html()', function(){ + it('should return inner HTML', function(){ + var $ = helix(document.querySelector('.person').cloneNode(true)); + $('a').html().should.equal('about'); + }) }) - it('should set inner HTML', function(){ - var $ = helix(document.querySelector('.person').cloneNode(true)); - $('a').html('lol'); - $('a').html().should.equal('lol'); + describe('#html(val)', function(){ + it('should set inner HTML', function(){ + var $ = helix(document.querySelector('.person').cloneNode(true)); + $('a').html('lol'); + $('a').html().should.equal('lol'); + }) }) -}) -describe('attributes', function(){ - it('should return existing attribute value', function(){ - var $ = helix(document.querySelector('.person').cloneNode(true)); - $('a').href().should.equal('/about'); + describe('#[attr]()', function(){ + it('should return existing attribute value', function(){ + var $ = helix(document.querySelector('.person').cloneNode(true)); + $('a').href().should.equal('/about'); + }) }) - it('should change attribute value', function(){ - var $ = helix(document.querySelector('.person').cloneNode(true)); - $('a').href('/me'); - $('a').href().should.equal('/me'); + describe('#[attr](val)', function(){ + it('should change the attribute value', function(){ + var $ = helix(document.querySelector('.person').cloneNode(true)); + $('a').href('/me'); + $('a').href().should.equal('/me'); + }) }) - it('should add new attribute', function(){ - var $ = helix(document.querySelector('.person').cloneNode(true)); - $('.name').attr('data-type', 'first'); - $('.name').attr('data-type').should.equal('first'); + describe('#attr(attr, val)', function(){ + it('should add a new attribute', function(){ + var $ = helix(document.querySelector('.person').cloneNode(true)); + $('.name').attr('data-type', 'first'); + $('.name').attr('data-type').should.equal('first'); + }) }) -}) -describe('classes', function(){ - it('should add a new class', function(){ - var $ = helix(document.querySelector('.person').cloneNode(true)); - $('a').addClass('link'); - $('a').classes.contains('link').should.equal(true); + describe('#addClass()', function(){ + it('should add a new class', function(){ + var $ = helix(document.querySelector('.person').cloneNode(true)); + $('a').addClass('link'); + $('a').classes.contains('link').should.equal(true); + }) }) - it('should remove a class', function(){ - var $ = helix(document.querySelector('body').cloneNode(true)); - $('div').classes.contains('person').should.equal(true); - $('div').removeClass('person'); - $('div').classes.contains('person').should.equal(false); + describe('#removeClass()', function(){ + it('should remove a class', function(){ + var $ = helix(document.querySelector('body').cloneNode(true)); + $('div').classes.contains('person').should.equal(true); + $('div').removeClass('person'); + $('div').classes.contains('person').should.equal(false); + }) }) - it('should toggle a class', function(){ - var $ = helix(document.querySelector('body').cloneNode(true)); - $('div').classes.contains('person').should.equal(true); - $('div').toggle('person'); - $('div').classes.contains('person').should.equal(false); - $('div').toggle('person'); - $('div').classes.contains('person').should.equal(true); + describe('#toggle()', function(){ + it('should toggle a class', function(){ + var $ = helix(document.querySelector('body').cloneNode(true)); + $('div').classes.contains('person').should.equal(true); + $('div').toggle('person'); + $('div').classes.contains('person').should.equal(false); + $('div').toggle('person'); + $('div').classes.contains('person').should.equal(true); + }) }) })