Skip to content

Commit

Permalink
Complete tests for the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
apsdehal committed Apr 26, 2015
1 parent c2be76c commit ec3b8a8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
21 changes: 18 additions & 3 deletions tests/test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
var assert = require('assert')
var assert = require('chai').assert,
utils = require('./utils');

var $ = utils.getSelectorObject();

describe('Main module', function () {
it('should contain a link for all title', function () {
it('should contain a non-duplicate link for all title', function () {
var links = [];

$('a').each(function (k) {
var href = $(this).attr('href');

assert.isDefined(href, 'Expected href for ' + $(this).html());

if (links[href]) {
console.log(href);
assert.ok(false, 'Duplicate link for ' + $(this).html());
}

links[href] = true;
});
});

it('should be sorted alphabetically', function () {

$('ul').each(function () {
utils.testList(assert, $, $(this));
})
});
})
29 changes: 26 additions & 3 deletions tests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,33 @@ var fs = require('fs'),
cheerio = require('cheerio');

module.exports = (function () {
return {
var utils = {
getSelectorObject: function () {
var html = marked(fs.readFileSync('../README.md'));
var html = marked(fs.readFileSync('./README.md', 'utf-8'));
return cheerio.load(html);
},
}

testList: function (assert, $, list) {
var self = this;

list.find('ul').each(function () {
utils.testList(assert, $, $(this));
$(this).remove('ul');
});
self.testAlphabetical(assert, $, list);
},

testAlphabetical: function (assert, $, list) {
var items = [];
list.find("li > a:first-child").map(function (i) {
items.push($(this).text().toLowerCase());
});

sorted = items.slice().sort();

assert.deepEqual(items, sorted, 'Links should be in alphabetical order');
}
};

return utils;
})();

0 comments on commit ec3b8a8

Please sign in to comment.