forked from helpers/handlebars-helpers
-
Notifications
You must be signed in to change notification settings - Fork 4
/
misc.js
67 lines (59 loc) · 2.25 KB
/
misc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const assert = require('assert');
const hbs = require('handlebars').create();
const helpers = require('..');
describe('misc', function() {
beforeEach(function() {
helpers.misc({ handlebars: hbs });
});
describe('noop', function() {
it('should be a noop', function() {
const fn = hbs.compile('{{#noop}}{{message}}{{/noop}}');
assert.equal(fn({message: 'This is a test'}), 'This is a test');
});
});
describe('option', function() {
it('should get an option', function() {
const fn = hbs.compile('{{option "a"}}');
assert.equal(fn({options: {a: 'bbb'}}), 'bbb');
});
it('should return an empty string when no options are found', function() {
assert.equal(hbs.compile('{{option "a"}}')(), '');
});
it('should get a nested option', function() {
const fn = hbs.compile('{{option "a.b.c"}}');
assert.equal(fn({options: {a: {b: {c: 'ddd'}}}}), 'ddd');
});
it('should work as a subexpression', function() {
const fn = hbs.compile('{{option "a.b.c"}}');
assert.equal(fn({options: {a: {b: {c: 'ddd'}}}}), 'ddd');
});
});
describe('typeOf', function() {
it('should return the type of a string', function() {
const fn = hbs.compile('{{typeOf value}}');
assert.equal(fn({ value: 'foo' }), 'string');
});
it('should return the type of a number', function() {
const fn = hbs.compile('{{typeOf value}}');
assert.equal(fn({ value: 1 }), 'number');
});
});
describe('md5', () => {
it('returns the md5 hash of the parameter', function() {
const fn = hbs.compile('{{md5 name}}');
assert.equal(fn({ name: 'john' }), '527bd5b5d689e2c32ae974c6229ff785');
});
it('returns md5 only of the first parameter', function() {
const fn = hbs.compile('{{md5 name age}}');
assert.equal(fn({ name: 'john', age: '25' }), '527bd5b5d689e2c32ae974c6229ff785');
});
it('returns md5 as empty string if null is passed to it. ', function() {
const fn = hbs.compile('{{md5 name}}');
assert.equal(fn({ name: null }), '');
});
it('returns md5 as empty string if undefined is passed to it. ', function() {
const fn = hbs.compile('{{md5 name}}');
assert.equal(fn({ name: undefined }), '');
});
});
});