Complete tests for the repo

This commit is contained in:
Amanpreet Singh 2015-04-26 13:34:49 +05:30
parent c2be76c7fe
commit ec3b8a8c3b
2 changed files with 44 additions and 6 deletions

View file

@ -1,14 +1,29 @@
var assert = require('assert') var assert = require('chai').assert,
utils = require('./utils'); utils = require('./utils');
var $ = utils.getSelectorObject(); var $ = utils.getSelectorObject();
describe('Main module', function () { 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 () { it('should be sorted alphabetically', function () {
$('ul').each(function () {
utils.testList(assert, $, $(this));
})
}); });
}) })

View file

@ -3,10 +3,33 @@ var fs = require('fs'),
cheerio = require('cheerio'); cheerio = require('cheerio');
module.exports = (function () { module.exports = (function () {
return { var utils = {
getSelectorObject: function () { getSelectorObject: function () {
var html = marked(fs.readFileSync('../README.md')); var html = marked(fs.readFileSync('./README.md', 'utf-8'));
return cheerio.load(html); 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;
})(); })();