Skip to content

Commit befbb0c

Browse files
Merge pull request #283 from DenSpirit/master
Add 'falsey' to dependencies and write tests for isTruthy/isFalsey
2 parents 20687c4 + 31ef162 commit befbb0c

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ Visit the: [code](lib/comparison.js) | [unit tests](test/comparison.js) | [issue
166166
* **[gt](#gt)** ([code](lib/comparison.js#L182) | [tests](test/comparison.js#L214))
167167
* **[gte](#gte)** ([code](lib/comparison.js#L206) | [tests](test/comparison.js#L245))
168168
* **[has](#has)** ([code](lib/comparison.js#L226) | [tests](test/comparison.js#L260))
169-
* **[isFalsey](#isFalsey)** ([code](lib/comparison.js#L268) | [no tests])
170-
* **[isTruthy](#isTruthy)** ([code](lib/comparison.js#L283) | [no tests])
169+
* **[isFalsey](#isFalsey)** ([code](lib/comparison.js#L268) | [tests](test/comparison.js#L327))
170+
* **[isTruthy](#isTruthy)** ([code](lib/comparison.js#L283) | [tests](test/comparison.js#L339))
171171
* **[ifEven](#ifEven)** ([code](lib/comparison.js#L304) | [tests](test/comparison.js#L344))
172172
* **[ifNth](#ifNth)** ([code](lib/comparison.js#L321) | [tests](test/comparison.js#L356))
173173
* **[ifOdd](#ifOdd)** ([code](lib/comparison.js#L344) | [tests](test/comparison.js#L379))

lib/utils/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ require('kind-of', 'typeOf');
1818
// matching utils
1919
require('is-glob');
2020
require('micromatch', 'mm');
21+
require('falsey');
2122

2223
// Number utils
2324
require('is-even');

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"array-sort": "^0.1.2",
7373
"create-frame": "^1.0.0",
7474
"define-property": "^1.0.0",
75+
"falsey": "^0.3.0",
7576
"for-in": "^1.0.2",
7677
"for-own": "^1.0.0",
7778
"get-object": "^0.2.0",

test/comparison.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,30 @@ describe('comparison', function() {
324324
});
325325
});
326326

327+
describe('isFalsey', function() {
328+
it('should render block if given value is falsey.', function() {
329+
var fn = hbs.compile('{{#if (isFalsey value)}}A{{else}}B{{/if}}');
330+
assert.equal(fn({value: 'nope'}), 'A');
331+
});
332+
333+
it('should render inverse if given value is truthy', function() {
334+
var fn = hbs.compile('{{#if (isFalsey value)}}A{{else}}B{{/if}}');
335+
assert.equal(fn({value: 'CCC'}), 'B');
336+
});
337+
});
338+
339+
describe('isTruthy', function() {
340+
it('should render block if given value is truthy.', function() {
341+
var fn = hbs.compile('{{#if (isTruthy value)}}A{{else}}B{{/if}}');
342+
assert.equal(fn({value: 'CCC'}), 'A');
343+
});
344+
345+
it('should render inverse if given value is not truthy', function() {
346+
var fn = hbs.compile('{{#if (isTruthy value)}}A{{else}}B{{/if}}');
347+
assert.equal(fn({value: 'nope'}), 'B');
348+
});
349+
});
350+
327351
describe('eq', function() {
328352
it('should render a block if the value is equal to a given number.', function() {
329353
var fn = hbs.compile('{{#eq number compare=8}}A{{/eq}}');

0 commit comments

Comments
 (0)