-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
conditional.js
70 lines (60 loc) · 2.62 KB
/
conditional.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
68
69
70
/*!
* template-helpers <https://github.com/jonschlinkert/template-helpers>
*
* Copyright (c) 2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
'use strict';
var assert = require('assert');
var helpers = require('..')('conditional');
var template = require('lodash.template');
var imports = {imports: helpers};
var context = {
fn: function(a, b) {
return this && this.foo === 'abc';
},
thisArg: {foo: 'abc', bar: 'xyz'}
};
describe('conditional', function() {
describe('if', function() {
it('should return an empty string when the first arg is not a function.', function() {
assert.equal(template('<%= _if("foo", "bar", thisArg) %>', imports)(context), '');
});
it('should return the first value when `fn` returns true.', function() {
assert.equal(template('<%= _if(fn, "foo", "bar", thisArg) %>', imports)(context), 'foo');
});
it('should return the second value when `fn` returns false.', function() {
assert.equal(template('<%= _if(fn, "foo", "bar") %>', imports)(context), 'bar');
});
});
describe('compare', function() {
it('should be true when values are equal', function() {
assert.equal(template('<%= compare("foo", "===", "foo") %>', imports)(context), 'true');
assert.equal(template('<%= compare("foo", "==", "foo") %>', imports)(context), 'true');
});
it('should be false when values are not equal', function() {
assert.equal(template('<%= compare("foo", "===", "bar") %>', imports)(context), 'false');
assert.equal(template('<%= compare("foo", "==", "bar") %>', imports)(context), 'false');
});
});
describe('is / eq', function() {
it('should be true when values are equal', function() {
assert.equal(template('<%= is("foo", "foo") %>', imports)(context), 'true');
assert.equal(template('<%= eq("foo", "foo") %>', imports)(context), 'true');
});
it('should be false when values are not equal', function() {
assert.equal(template('<%= is("foo", "bar") %>', imports)(context), 'false');
assert.equal(template('<%= eq("foo", "bar") %>', imports)(context), 'false');
});
});
describe('isnt / notEq', function() {
it('should be false when values are equal', function() {
assert.equal(template('<%= isnt("foo", "foo") %>', imports)(context), 'false');
assert.equal(template('<%= notEq("foo", "foo") %>', imports)(context), 'false');
});
it('should be true when values are not equal', function() {
assert.equal(template('<%= isnt("foo", "bar") %>', imports)(context), 'true');
assert.equal(template('<%= notEq("foo", "bar") %>', imports)(context), 'true');
});
});
});