Skip to content
This repository has been archived by the owner on Dec 2, 2023. It is now read-only.

Commit

Permalink
add image tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sixertoy committed Aug 18, 2015
1 parent 30ef3f1 commit c150fc2
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 13 deletions.
6 changes: 0 additions & 6 deletions spec/src/equal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,15 @@
afterEach(function () {});

describe('register', function () {

it('handlebars registerHelper called once', function () {
sinon.spy(handlebars, 'registerHelper');
helper.register();
expect(handlebars.registerHelper.callCount).to.equal(1);
handlebars.registerHelper.restore();
});

});

describe('render', function () {

it('throws missing arguments', function () {
expect(function () {
helper.render();
Expand All @@ -57,21 +54,18 @@
helper.render(true, handlebarsOptions);
}).to.throw('missing arguments');
});

it('not throws missing arguments', function () {
expect(function () {
helper.render(true, false, handlebarsOptions);
}).not.to.throw('missing arguments');
});

it('handlebars createFrame called', function () {
sinon.spy(handlebars, 'createFrame');
helper.register();
helper.render(true, false, handlebarsOptions);
expect(handlebars.createFrame.callCount).to.equal(1);
handlebars.createFrame.restore();
});

});

describe('isequal', function () {
Expand Down
69 changes: 69 additions & 0 deletions spec/src/image.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*jshint unused: false */
/*jslint indent: 4, nomen: true */
/*global __dirname, jasmine, process, require, define, describe, xdescribe, it, xit, expect, beforeEach, afterEach, afterLast, console */
(function() {
'use strict';
var //variables
helper, result,
cwd = process.cwd(),
// requires
path = require('path'),
sinon = require('sinon'),
expect = require('chai').expect,
handlebars = require('handlebars'),
Image = require(path.join(cwd, 'src/helpers/image.js'));
describe('image', function() {
beforeEach(function() {
helper = new Image();
});
afterEach(function() {});
describe('register', function() {
it('handlebars registerHelper called once', function() {
sinon.spy(handlebars, 'registerHelper');
helper.register();
expect(handlebars.registerHelper.callCount).to.equal(1);
handlebars.registerHelper.restore();
});
});
describe('render', function() {
it('throws missing arguments', function() {
helper.register();
expect(function(){
helper.render();
}).to.throw('missing arguments');
});
it('not throws missing arguments', function() {
helper.register();
expect(function(){
helper.render({name: '$image'});
}).not.to.throw('missing arguments');
});
});
describe('returns an image of 300x300', function() {
it('no width no height (300 default)', function() {
helper.register();
result = helper.render({name: '$image'});
expect(result.toString()).to.equal('<img src="//placehold.it/300x300" alt="" title="" />');
});
it('width 300 no height (300 default)', function() {
helper.register();
result = helper.render(300, {name: '$image'});
expect(result.toString()).to.equal('<img src="//placehold.it/300x300" alt="" title="" />');
});
});
describe('returns an image of 400x400', function() {
it('width 400 no height (same as width)', function() {
helper.register();
result = helper.render(400, {name: '$image'});
expect(result.toString()).to.equal('<img src="//placehold.it/400x400" alt="" title="" />');
});
});
describe('returns an image of 500x220', function() {
it('width 500 height 220', function() {
helper.register();
result = helper.render(500, 220, {name: '$image'});
expect(result.toString()).to.equal('<img src="//placehold.it/500x220" alt="" title="" />');
});
});
});
}());
12 changes: 6 additions & 6 deletions spec/stories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ src/helpers/image.js:
- throws missing arguments
- not throws missing arguments
returns an image of 300x300:
no width no height:
no height:
height 300:
returns an image of 400x300:
returns an image of 300x400:
height 300:
- no width no height (300 default)
- width 300 no height (300 default)
returns an image of 400x400:
- width 400 no height (same as width)
returns an image of 500x220:
- width 500 height 220
4 changes: 3 additions & 1 deletion src/helpers/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@
height = false;
}
width = isnumber(width) ? width : 300;
result = 'http://placehold.it/' + width;
result = '//placehold.it/' + width;
if (isnumber(height)) {
result += 'x' + height;
} else {
result += 'x' + width;
}
return new Handlebars.SafeString('<img src="' + result + '" alt="" title="" />');
};
Expand Down

0 comments on commit c150fc2

Please sign in to comment.