Skip to content

Commit

Permalink
Added test for incorrect LoadingResource operation
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelmeister committed Aug 18, 2024
1 parent 484b275 commit d88db92
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Collection<ItemType extends ResourceInterface, ResourceType extends Collec
/**
* Returns a promise that resolves to the collection object, once all items have been loaded
*/
public $loadItems () :Promise<this> {
public $loadItems (): Promise<this> {
return this._itemLoader(this._storeData.items)
}

Expand Down
20 changes: 20 additions & 0 deletions tests/apiOperations.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit d88db92

Please sign in to comment.