From d88db927c486c2ea6dde9704f9b9054afebedcbe Mon Sep 17 00:00:00 2001 From: Manuel Meister Date: Sun, 18 Aug 2024 22:45:28 +0200 Subject: [PATCH] Added test for incorrect LoadingResource operation --- src/Collection.ts | 2 +- tests/apiOperations.spec.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Collection.ts b/src/Collection.ts index 09a06db6..4ffa125c 100644 --- a/src/Collection.ts +++ b/src/Collection.ts @@ -33,7 +33,7 @@ class Collection { + public $loadItems (): Promise { return this._itemLoader(this._storeData.items) } diff --git a/tests/apiOperations.spec.js b/tests/apiOperations.spec.js index ccb3b45f..95742c45 100644 --- a/tests/apiOperations.spec.js +++ b/tests/apiOperations.spec.js @@ -493,6 +493,26 @@ describe('Using dollar methods', () => { expect(result[0]).toMatchObject({ id: 123, _meta: { self: '/items/123' } }) }) + it('does throw when $loadItems is called on a non-collection entity', async () => { + // given + const userResponse = { + id: 2, + _links: { + self: { + href: '/users/2' + } + } + } + axiosMock.onGet('http://localhost/users/2').replyOnce(200, userResponse) + + const user = vm.api.get('/users/2') + expect(user).toBeInstanceOf(LoadingResource) + + // then + expect(user.$loadItems()).rejects.toThrow('This LoadingResource is not a collection') + await letNetworkRequestFinish() + }) + it('loads the contents of an embedded collection', async () => { // given const userResponse = {