Permalink
Browse files

WS

  • Loading branch information...
1 parent 0b1e403 commit 84d5895376b2ade76f75e2e8d368b96aa2109b20 @ericclemmons committed Mar 27, 2013
Showing with 42 additions and 49 deletions.
  1. +1 −1 index.js
  2. +41 −48 test/unique-selector.js
View
2 index.js
@@ -28,7 +28,7 @@ function unique(el) {
// Recalculate index based on position of el amongst siblings
i = [].indexOf.call(el.parentNode.children, el);
- selector += ':nth-child(' + (i + 1) +')';
+ selector += ':nth-child(' + (i + 1) + ')';
break;
}
}
View
89 test/unique-selector.js
@@ -1,62 +1,55 @@
var unique = require('unique-selector');
function assert(expr, msg) {
- if (!expr) throw new Error(msg || 'failed');
+ if (!expr) throw new Error(msg || 'failed');
}
describe('unique-selector', function() {
- describe('with undefined', function() {
- it('should return a TypeError', function() {
- try {
- unique();
- assert(false);
- } catch(e) {
- assert(e instanceof TypeError);
- }
- });
+ describe('with undefined', function() {
+ it('should return a TypeError', function() {
+ try {
+ unique();
+ assert(false);
+ } catch (e) {
+ assert(e instanceof TypeError);
+ }
});
+ });
- describe('with Object', function() {
- it('should return a TypeError', function() {
- try {
- unique({});
- assert(false);
- } catch(e) {
- assert(e instanceof TypeError);
- }
- });
+ describe('with Object', function() {
+ it('should return a TypeError', function() {
+ try {
+ unique({});
+ assert(false);
+ } catch (e) {
+ assert(e instanceof TypeError);
+ }
});
+ });
- var selectors = {
- // Selector: expected
- 'HTML > BODY':
- 'html > body',
- 'HTML > BODY > DIV#fixture':
- '#fixture',
- 'HTML > BODY > DIV#fixture > H3 > SMALL':
- '#fixture > h3 > small',
- 'HTML > BODY > DIV#fixture > UL#nav > LI:nth-child(1)':
- '#nav > li.first.item',
- 'HTML > BODY > DIV#fixture > UL#nav > LI:nth-child(2)':
- '#nav > li.collapsed.item:nth-child(2)',
- 'HTML > BODY > DIV#fixture > UL#nav > LI:nth-child(3)':
- '#nav > li.last.collapsed.item',
- 'HTML > BODY > DIV#fixture > UL#nav > LI.item > UL#nested > LI.child > IMG':
- '#nested > li.child > img[alt="Some Title"]'
- };
+ var selectors = {
+ // Selector: expected
+ 'HTML > BODY': 'html > body',
+ 'HTML > BODY > DIV#fixture': '#fixture',
+ 'HTML > BODY > DIV#fixture > H3 > SMALL': '#fixture > h3 > small',
+ 'HTML > BODY > DIV#fixture > UL#nav > LI:nth-child(1)': '#nav > li.first.item',
+ 'HTML > BODY > DIV#fixture > UL#nav > LI:nth-child(2)': '#nav > li.collapsed.item:nth-child(2)',
+ 'HTML > BODY > DIV#fixture > UL#nav > LI:nth-child(3)': '#nav > li.last.collapsed.item',
+ 'HTML > BODY > DIV#fixture > UL#nav > LI.item > UL#nested > LI.child > IMG': '#nested > li.child > img[alt="Some Title"]'
+ };
- for (selector in selectors) {
- describe('with ' + selector, function() {
- var expected = selectors[selector];
- var actual = unique(document.querySelector(selector));
+ for (selector in selectors) {
+ describe('with ' + selector, function() {
+ var expected = selectors[selector];
+ var actual = unique(document.querySelector(selector));
- it('should return `' + expected + '`', function() {
- assert(expected === actual, actual);
- });
+ it('should return `' + expected + '`', function() {
+ assert(expected === actual, actual);
+ });
- it('should have only 1 match', function() {
- assert(1 === document.querySelectorAll(selector).length);
- });
- });
- }
+ it('should have only 1 match', function() {
+ assert(1 === document.querySelectorAll(selector).length);
+ });
+ });
+ }
});

0 comments on commit 84d5895

Please sign in to comment.