diff --git a/addon/adapters/rest.js b/addon/adapters/rest.js index 81fb9273da7..7cded79adb2 100644 --- a/addon/adapters/rest.js +++ b/addon/adapters/rest.js @@ -993,13 +993,15 @@ export default Adapter.extend(BuildURLMixin, { }, buildQuery(snapshot) { - const { include } = snapshot; - let query = {}; if (isEnabled('ds-finder-include')) { - if (include) { - query.include = include; + if(snapshot) { + const { include } = snapshot; + + if (include) { + query.include = include; + } } } diff --git a/tests/unit/adapters/rest-adapter/build-query-test.js b/tests/unit/adapters/rest-adapter/build-query-test.js index fa098e56c2e..6632346548d 100644 --- a/tests/unit/adapters/rest-adapter/build-query-test.js +++ b/tests/unit/adapters/rest-adapter/build-query-test.js @@ -13,6 +13,13 @@ test("buildQuery() returns an empty query when snapshot has no query params", fu assert.deepEqual(query, {}, 'query is empty'); }); +test("buildQuery - doesn't fail without a snapshot", function(assert) { + const adapter = DS.RESTAdapter.create(); + const query = adapter.buildQuery(); + + assert.deepEqual(query, {}, 'returns an empty query'); +}); + if (isEnabled('ds-finder-include')) { test("buildQuery() returns query with `include` from snapshot", function(assert) { const adapter = DS.RESTAdapter.create();