From 3550893b12c9b371efbd8d18d8dfa352d9fb2026 Mon Sep 17 00:00:00 2001 From: Alex Navasardyan Date: Tue, 21 May 2019 19:17:29 -0400 Subject: [PATCH] Make sure `findOne` throws if no elements are found --- addon-test-support/-private/properties/collection.js | 2 +- tests/acceptance/collection-test.js | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/addon-test-support/-private/properties/collection.js b/addon-test-support/-private/properties/collection.js index 2a1dc6a..fdf28b4 100644 --- a/addon-test-support/-private/properties/collection.js +++ b/addon-test-support/-private/properties/collection.js @@ -53,7 +53,7 @@ class CollectionProxy { findOne(query) { let result = this.findAll(query); - assert(`Expected at most one result from findOne query, but found ${result.length}`, result.length <= 1); + assert(`Expected at most one result from 'findOne' query in '${this._collection.key}' collection, but found ${result.length}`, result.length === 1); return result[0]; } diff --git a/tests/acceptance/collection-test.js b/tests/acceptance/collection-test.js index 305aad6..8fdb5a3 100644 --- a/tests/acceptance/collection-test.js +++ b/tests/acceptance/collection-test.js @@ -37,9 +37,9 @@ test('collection works as expected', function(assert) { assert.equal(list.items.findOne((i) => i.isActive).text, 'Bar'); assert.equal(list.items.findOne({ text: 'Bar', isActive: true }).text, 'Bar'); - assert.equal(list.items.findOne({ text: 'Foo', isActive: true }), undefined); + assert.throws(() => assert.equal(list.items.findOne({ text: 'Foo', isActive: true }), /Expected at most one result from 'findOne' query in 'foos' collection, but found 0/)); - assert.throws(() => list.items.findOne((i) => i.isActive || i.text === 'Foo'), /Expected at most one result from findOne query, but found 2/); + assert.throws(() => list.items.findOne((i) => i.isActive || i.text === 'Foo'), /Expected at most one result from 'findOne' query in 'items' collection, but found 2/); }); }); @@ -62,7 +62,6 @@ test('collections do not share instances of proxies', function(assert) { }); }); - test('Collection works with PageObject definition', function(assert) { let bar = new PageObject({ scope: '[data-test-simple-list-wrapper]',