Skip to content

Commit

Permalink
sync up tests with assemble-core
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschlinkert committed May 26, 2016
1 parent f7ad503 commit 26b3385
Show file tree
Hide file tree
Showing 26 changed files with 823 additions and 333 deletions.
8 changes: 4 additions & 4 deletions test/app.applyLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ describe('app.applyLayout', function() {
app.layout('fofof.tmpl', {content: '..'});
app.page('a.tmpl', page)
.render(function(err) {
assert.equal(err.message, 'Templates#layouts layout "default.tmpl" was defined on view "a.tmpl" but cannot be not found (common causes are incorrect glob patterns, renameKey function modifying the key, and typos in search pattern)');
assert(/layouts/.test(err.message));
cb();
});
});

it('should emit an error when a layout cannot be found:', function(cb) {
app.layout('fofof.tmpl', {content: '..'});
app.on('error', function(err) {
assert.equal(err.message, 'Templates#layouts layout "default.tmpl" was defined on view "a.tmpl" but cannot be not found (common causes are incorrect glob patterns, renameKey function modifying the key, and typos in search pattern)');
assert(/layouts/.test(err.message));
cb();
});

Expand All @@ -47,14 +47,14 @@ describe('app.applyLayout', function() {
it('should throw an error - layout defined but no layouts registered:', function(cb) {
app.page('a.tmpl', page)
.render(function(err) {
assert.equal(err.message, 'Templates#layouts layout "default.tmpl" was defined on view "a.tmpl" but no layouts are registered');
assert(/layouts/.test(err.message));
cb();
});
});

it('should emit an error - layout defined but no layouts registered:', function(cb) {
app.on('error', function(err) {
assert.equal(err.message, 'Templates#layouts layout "default.tmpl" was defined on view "a.tmpl" but no layouts are registered');
assert(/layouts/.test(err.message));
cb();
});
app.page('a.tmpl', page)
Expand Down
10 changes: 7 additions & 3 deletions test/app.collection.render.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ describe('app.collection.render', function() {
pages.engine('tmpl', require('engine-base'));
});

it('should throw an error when no callback is given:', function() {
(function() {
it('should throw an error when no callback is given:', function(cb) {
try {
app.pages.render({});
}).should.throw('Views#render is async and expects a callback function');
cb(new Error('expected an error'));
} catch (err) {
assert.equal(err.message, 'Views#render is async and expects a callback function');
cb();
}
});

it('should throw an error when an engine is not defined:', function(cb) {
Expand Down
44 changes: 18 additions & 26 deletions test/app.create.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ describe('app.create', function() {
});

it('should expose the create method', function() {
assert(typeof app.create === 'function');
assert.equal(typeof app.create, 'function');
});

it('should add a collection to `views`', function() {
app.create('pages');
assert(typeof app.views.pages === 'object');
assert(typeof app.pages === 'function');
assert.equal(typeof app.views.pages, 'object');
assert.equal(typeof app.pages, 'function');
});

it('should add a pluralized collection to `views`', function() {
app.create('page');
assert(typeof app.views.pages === 'object');
assert(typeof app.page === 'function');
assert.equal(typeof app.views.pages, 'object');
assert.equal(typeof app.page, 'function');
});
});

Expand All @@ -45,9 +45,9 @@ describe('app.create', function() {
assert(app.views.pages.hasOwnProperty('foo'));
});

it('should add view Ctor names to views', function() {
it('should add view collection name to view._name', function() {
app.pages.addView('foo', {content: 'bar'});
assert(app.views.pages.foo._name === 'page');
assert.equal(app.views.pages.foo._name, 'page');
});

it('should add partial views when partial type is defined', function() {
Expand All @@ -72,8 +72,8 @@ describe('app.create', function() {
app.partials.addView('foo', {content: 'bar'});
var view = app.partials.getView('foo');
assert(view.isType('partial'));
assert(!view.isType('renderable'));
assert(!view.isType('layout'));
assert(!view.isType('renderable'));
});

it('should set viewType on layout views', function() {
Expand Down Expand Up @@ -126,7 +126,7 @@ describe('app.create', function() {
var a = app.pages.getView('a.hbs');
assert(a instanceof Vinyl);
assert(Vinyl.isVinyl(a));
assert(typeof a.read === 'function');
assert.equal(typeof a.read, 'function');

views.addView('d.hbs', {path: 'd.hbs', content: 'd'});
var d = app.pages.getView('d.hbs');
Expand All @@ -147,7 +147,7 @@ describe('app.create', function() {
app.page('b.hbs', {content: 'b'});
app.page('c.hbs', {content: 'c'});
app.views.pages.should.have.properties(['a.hbs', 'b.hbs', 'c.hbs']);
assert(app.views.pages['a.hbs'].contents.toString() === 'a');
assert.equal(app.views.pages['a.hbs'].contents.toString(), 'a');
});

it('should create views from file paths:', function() {
Expand Down Expand Up @@ -180,13 +180,15 @@ describe('app.create', function() {
.use(function(views) {
views.read = function(name) {
var view = this.getView(name);
view.contents = fs.readFileSync(view.path);
if (!view.contents) {
view.contents = fs.readFileSync(view.path);
}
};
});

collection.addView('test/fixtures/templates/a.tmpl');
collection.read('a.tmpl');
assert(collection.getView('a.tmpl').contents.toString() === '<%= name %>');
assert.equal(collection.getView('a.tmpl').contents.toString(), '<%= name %>');
});
});

Expand All @@ -198,7 +200,7 @@ describe('app.create', function() {

it('should add collection to the given viewType', function() {
app.create('layout', {viewType: 'layout'});
assert(app.layouts.options.viewType[0] === 'layout');
assert.equal(app.layouts.options.viewType[0], 'layout');
});

it('should add a collection to multiple viewTypes', function() {
Expand All @@ -213,17 +215,7 @@ describe('app.create', function() {
app.engine('tmpl', require('engine-base'));
});

it('should emit `create` before a collection is created:', function() {
app.on('create', function(name, options) {
options.viewType = 'partial';
});

app.create('includes');
app.include('one', {path: 'two', contents: '...'});
assert(app.includes.isType('partial'));
});

it('should emit `postCreate` after a collection is created:', function() {
it('should emit `create` when a collection is created:', function() {
app.on('postCreate', function(collection) {
if (collection.options.plural === 'layouts') {
collection.options.foo = 'bar';
Expand All @@ -232,7 +224,7 @@ describe('app.create', function() {

app.create('layout');
app.layout('one', {path: 'two', contents: '...'});
assert(app.layouts.options.foo === 'bar');
assert.equal(app.layouts.options.foo, 'bar');
});
});

Expand All @@ -246,7 +238,7 @@ describe('app.create', function() {
});

assert(app.pages.foo);
assert(typeof app.pages.foo === 'function');
assert.equal(typeof app.pages.foo, 'function');
});
});
});
Loading

0 comments on commit 26b3385

Please sign in to comment.