Skip to content

Commit

Permalink
Merge pull request helpers#283 from DenSpirit/master
Browse files Browse the repository at this point in the history
Add 'falsey' to dependencies and write tests for isTruthy/isFalsey
  • Loading branch information
jonschlinkert authored Jul 28, 2017
2 parents 20687c4 + 31ef162 commit befbb0c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ Visit the: [code](lib/comparison.js) | [unit tests](test/comparison.js) | [issue
* **[gt](#gt)** ([code](lib/comparison.js#L182) | [tests](test/comparison.js#L214))
* **[gte](#gte)** ([code](lib/comparison.js#L206) | [tests](test/comparison.js#L245))
* **[has](#has)** ([code](lib/comparison.js#L226) | [tests](test/comparison.js#L260))
* **[isFalsey](#isFalsey)** ([code](lib/comparison.js#L268) | [no tests])
* **[isTruthy](#isTruthy)** ([code](lib/comparison.js#L283) | [no tests])
* **[isFalsey](#isFalsey)** ([code](lib/comparison.js#L268) | [tests](test/comparison.js#L327))
* **[isTruthy](#isTruthy)** ([code](lib/comparison.js#L283) | [tests](test/comparison.js#L339))
* **[ifEven](#ifEven)** ([code](lib/comparison.js#L304) | [tests](test/comparison.js#L344))
* **[ifNth](#ifNth)** ([code](lib/comparison.js#L321) | [tests](test/comparison.js#L356))
* **[ifOdd](#ifOdd)** ([code](lib/comparison.js#L344) | [tests](test/comparison.js#L379))
Expand Down
1 change: 1 addition & 0 deletions lib/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require('kind-of', 'typeOf');
// matching utils
require('is-glob');
require('micromatch', 'mm');
require('falsey');

// Number utils
require('is-even');
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"array-sort": "^0.1.2",
"create-frame": "^1.0.0",
"define-property": "^1.0.0",
"falsey": "^0.3.0",
"for-in": "^1.0.2",
"for-own": "^1.0.0",
"get-object": "^0.2.0",
Expand Down
24 changes: 24 additions & 0 deletions test/comparison.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,30 @@ describe('comparison', function() {
});
});

describe('isFalsey', function() {
it('should render block if given value is falsey.', function() {
var fn = hbs.compile('{{#if (isFalsey value)}}A{{else}}B{{/if}}');
assert.equal(fn({value: 'nope'}), 'A');
});

it('should render inverse if given value is truthy', function() {
var fn = hbs.compile('{{#if (isFalsey value)}}A{{else}}B{{/if}}');
assert.equal(fn({value: 'CCC'}), 'B');
});
});

describe('isTruthy', function() {
it('should render block if given value is truthy.', function() {
var fn = hbs.compile('{{#if (isTruthy value)}}A{{else}}B{{/if}}');
assert.equal(fn({value: 'CCC'}), 'A');
});

it('should render inverse if given value is not truthy', function() {
var fn = hbs.compile('{{#if (isTruthy value)}}A{{else}}B{{/if}}');
assert.equal(fn({value: 'nope'}), 'B');
});
});

describe('eq', function() {
it('should render a block if the value is equal to a given number.', function() {
var fn = hbs.compile('{{#eq number compare=8}}A{{/eq}}');
Expand Down

0 comments on commit befbb0c

Please sign in to comment.