Skip to content

Commit 9bd9916

Browse files
committed
increase code coverage
1 parent eb960c4 commit 9bd9916

File tree

2 files changed

+62
-6
lines changed

2 files changed

+62
-6
lines changed

test/comparison.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ describe('comparison', function() {
180180
assert.equal(fn({array: ['a', 'b', 'c']}), 'A');
181181
});
182182

183-
it('should render the block when an index is passed::', function() {
183+
it('should render the block when an index is passed:', function() {
184184
var fn = hbs.compile('{{#contains array "a" 0}}A{{else}}B{{/contains}}');
185185
assert.equal(fn({array: ['a', 'b', 'c']}), 'A');
186186
});
@@ -189,6 +189,16 @@ describe('comparison', function() {
189189
var fn = hbs.compile('{{#contains array "a" 1}}A{{else}}B{{/contains}}');
190190
assert.equal(fn({array: ['a', 'b', 'c']}), 'B');
191191
});
192+
193+
it('should not render the block when an undefined argument is passed:', function() {
194+
var fn = hbs.compile('{{#contains array nothing}}A{{/contains}}');
195+
assert.equal(fn({array: ['a', 'b', 'c']}), '');
196+
});
197+
198+
it('should render the inverse block when an undefined argument is passed:', function() {
199+
var fn = hbs.compile('{{#contains array nothing}}A{{else}}B{{/contains}}');
200+
assert.equal(fn({array: ['a', 'b', 'c']}), 'B');
201+
});
192202
});
193203

194204
describe('default', function() {

test/utils.js

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,59 @@
22

33
require('mocha');
44
var assert = require('assert');
5+
var utils = require('../lib/utils');
56
var HTML = require('../lib/utils/html');
67

7-
describe('html', function() {
8-
describe('parseAttributes', function() {
9-
it('should parse attributes', function() {
10-
assert.equal(HTML.parseAttributes({a: 'b', c: 200 }), 'a="b" c="200"');
8+
describe('utils', function() {
9+
describe('chop', function() {
10+
it('should return an empty string if undefined', function() {
11+
assert.equal(utils.chop(), '');
12+
});
13+
it('should remove non-word characters from start of string', function() {
14+
assert.equal(utils.chop('- foo bar baz'), 'foo bar baz');
15+
});
16+
it('should remove non-word characters from end of string', function() {
17+
assert.equal(utils.chop('foo bar baz _- '), 'foo bar baz');
1118
});
1219
});
13-
});
1420

21+
describe('changecase', function() {
22+
it('should return an empty string if undefined', function() {
23+
assert.equal(utils.changecase(), '');
24+
});
25+
it('should lowercase a mixed case string', function() {
26+
assert.equal(utils.changecase('fooBarBazQux'), 'foobarbazqux');
27+
});
28+
it('should lowercase a single character', function() {
29+
assert.equal(utils.changecase('f'), 'f');
30+
assert.equal(utils.changecase('A'), 'a');
31+
});
32+
});
33+
34+
describe('html', function() {
35+
describe('condense', function() {
36+
it('should condense multiple newlines into a single newline', function() {
37+
assert.equal(HTML.condense('foo\r\n \r\n bar\n'), 'foo\n\nbar\n');
38+
});
39+
});
40+
41+
describe('padcomments', function() {
42+
it('should add newlines around comments', function() {
43+
assert.equal(HTML.padcomments('<!-- foo -->'), '\n<!-- foo -->');
44+
});
45+
});
46+
47+
describe('parseAttributes', function() {
48+
it('should parse attributes', function() {
49+
assert.equal(HTML.parseAttributes({a: 'b', c: 200 }), 'a="b" c="200"');
50+
});
51+
});
52+
53+
describe('toAttributes', function() {
54+
it('should convert an object hash into html attributes', function() {
55+
var hash = {disabled: true, display: 'hidden', class: 'fade'};
56+
assert.equal(HTML.toAttributes(hash), ' disabled display="hidden" class="fade"');
57+
});
58+
});
59+
});
60+
});

0 commit comments

Comments
 (0)