metalsmith-collections/test/index.js

50 lines
1.5 KiB
JavaScript
Raw Normal View History

2014-02-05 15:06:46 -08:00
var assert = require('assert');
var Metalsmith = require('metalsmith');
var collections = require('..');
describe('metalsmith-collections', function(){
it('should add collections to metadata', function(done){
var metalsmith = Metalsmith('test/fixtures/basic');
metalsmith
.use(collections({ articles: {}}))
.build(function(err){
if (err) return done(err);
assert.equal(2, metalsmith.metadata().articles.length);
done();
});
});
it('should accept a "sortBy" option', function(done){
var metalsmith = Metalsmith('test/fixtures/sort');
metalsmith
.use(collections({ articles: { sortBy: 'title' }}))
.build(function(err){
if (err) return done(err);
var articles = metalsmith.metadata().articles;
assert.equal('Alpha', articles[0].title);
assert.equal('Beta', articles[1].title);
assert.equal('Gamma', articles[2].title);
done();
});
});
it('should accept a "reverse" option', function(done){
var metalsmith = Metalsmith('test/fixtures/sort');
metalsmith
.use(collections({
articles: {
sortBy: 'title',
reverse: true
}
}))
.build(function(err){
if (err) return done(err);
var articles = metalsmith.metadata().articles;
assert.equal('Alpha', articles[2].title);
assert.equal('Beta', articles[1].title);
assert.equal('Gamma', articles[0].title);
done();
});
});
});