Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find helper results null when query has empty result #15

Merged
merged 1 commit into from
Feb 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions addon-test-support/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export function keyEvent(selector, type, keyCode) {
@method find
@param {String|HTMLElement|NodeList} CSS selector to find one or more elements in the test DOM
@param {HTMLElement} contextEl to query within, query from its contained DOM
@return {HTMLElement|NodeList} one element or a (non-live) list of element objects
@return {null|HTMLElement|NodeList} null, one element or a (non-live) list of element objects
@public
*/
export function find(selector, contextEl) {
Expand All @@ -189,7 +189,7 @@ export function find(selector, contextEl) {
} else if (Object.prototype.toString.call(selector) === "[object String]") {
result = document.querySelectorAll(`${settings.rootElement} ${selector}`);
}
return (result.length === 1) ? result[0] : result;
return (result.length === 0) ? null : (result.length === 1) ? result[0] : result;
}


Expand Down
9 changes: 9 additions & 0 deletions tests/integration/find-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,12 @@ test('if a node list is passed to find instead of a selector it is returned', fu
let actual = find(expected);
assert.strictEqual(actual, expected, 'node list was returned from find');
});

test('with empty query result, find returns null', function(assert) {
this.render(hbs`
<div class='hiding'>You can't find me</div>
`);
let expected = null;
let actual = find('.hidden');
assert.strictEqual(actual, expected, 'null is returned for an empty query');
});