From 8abe3b3e327f8f7c328c97fd083dfd4992ad66d5 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Fri, 13 Apr 2018 19:24:59 +0200 Subject: [PATCH] Add `context` argument assertions to the `find` and `findAll` helpers --- addon-test-support/@ember/test-helpers/dom/find-all.js | 4 ++++ addon-test-support/@ember/test-helpers/dom/find.js | 4 ++++ tests/unit/dom/find-all-test.js | 6 ++++++ tests/unit/dom/find-test.js | 6 ++++++ 4 files changed, 20 insertions(+) diff --git a/addon-test-support/@ember/test-helpers/dom/find-all.js b/addon-test-support/@ember/test-helpers/dom/find-all.js index d9df140dc..a73cf5586 100644 --- a/addon-test-support/@ember/test-helpers/dom/find-all.js +++ b/addon-test-support/@ember/test-helpers/dom/find-all.js @@ -14,5 +14,9 @@ export default function find(selector) { throw new Error('Must pass a selector to `findAll`.'); } + if (arguments.length > 1) { + throw new Error('The `findAll` test helper only takes a single argument.'); + } + return toArray(getElements(selector)); } diff --git a/addon-test-support/@ember/test-helpers/dom/find.js b/addon-test-support/@ember/test-helpers/dom/find.js index b68615f03..421e7f4ed 100644 --- a/addon-test-support/@ember/test-helpers/dom/find.js +++ b/addon-test-support/@ember/test-helpers/dom/find.js @@ -13,5 +13,9 @@ export default function find(selector) { throw new Error('Must pass a selector to `find`.'); } + if (arguments.length > 1) { + throw new Error('The `find` test helper only takes a single argument.'); + } + return getElement(selector); } diff --git a/tests/unit/dom/find-all-test.js b/tests/unit/dom/find-all-test.js index 0ebcb9973..b1203ce12 100644 --- a/tests/unit/dom/find-all-test.js +++ b/tests/unit/dom/find-all-test.js @@ -63,4 +63,10 @@ module('DOM Helper: findAll', function(hooks) { findAll('#foo'); }, /Must setup rendering context before attempting to interact with elements/); }); + + test('throws if context argument is passed in', function(assert) { + assert.throws(() => { + findAll('#foo', document.querySelector('#ember-testing')); + }, /The `findAll` test helper only takes a single argument./); + }); }); diff --git a/tests/unit/dom/find-test.js b/tests/unit/dom/find-test.js index 72624bb2f..00b6c1e5b 100644 --- a/tests/unit/dom/find-test.js +++ b/tests/unit/dom/find-test.js @@ -49,4 +49,10 @@ module('DOM Helper: find', function(hooks) { find('#foo'); }, /Must setup rendering context before attempting to interact with elements/); }); + + test('throws if context argument is passed in', function(assert) { + assert.throws(() => { + find('#foo', document.querySelector('#ember-testing')); + }, /The `find` test helper only takes a single argument./); + }); });