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

Make sure findOne throws if no elements are found #24

Merged
merged 1 commit into from
Sep 3, 2019
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
2 changes: 1 addition & 1 deletion addon-test-support/-private/properties/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
5 changes: 2 additions & 3 deletions tests/acceptance/collection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
});
});

Expand All @@ -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]',
Expand Down