Skip to content

Commit

Permalink
add short-circuit tests for and and or helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Astapov committed Sep 2, 2023
1 parent b8e90e2 commit 3de805c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/test-app/tests/unit/helpers/and-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,22 @@ module('helper:and', function (hooks) {

assert.equal(this.element.textContent, '[2]', 'value should be "[2]"');
});

test('it does short-circuit with falsey argument', async function (assert) {
this.foo = {
get bar() {
assert.step('get bar');
return false;
},
get baz() {
assert.step('get baz');
return true;
},
};

await render(hbs`[{{and this.foo.bar this.foo.baz}}]`);

assert.verifySteps(['get bar']);
assert.dom().hasText('[false]');
});
});
18 changes: 18 additions & 0 deletions packages/test-app/tests/unit/helpers/or-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,22 @@ module('helper:or', function (hooks) {
'value should be "[ ] [yellow] [yellow] [ ]"'
);
});

test('it does short-circuit with truthy argument', async function (assert) {
this.foo = {
get bar() {
assert.step('get bar');
return true;
},
get baz() {
assert.step('get baz');
return false;
},
};

await render(hbs`[{{or this.foo.bar this.foo.baz}}]`);

assert.verifySteps(['get bar']);
assert.dom().hasText('[true]');
});
});

0 comments on commit 3de805c

Please sign in to comment.