Skip to content

Commit d4e9cbd

Browse files
committed
tests for improved error message
1 parent 7db8d0b commit d4e9cbd

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/store.spec.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,6 +1467,42 @@ describe('API store', () => {
14671467
expect(vm.api.get('/camps/1').emptyArray).toEqual([])
14681468
done()
14691469
})
1470+
1471+
it('throws error when accessing non-existing property like a relation', async done => {
1472+
// given
1473+
axiosMock.onGet('http://localhost/').reply(200, root.serverResponse)
1474+
1475+
// when
1476+
let loadingObject = null
1477+
loadingObject = vm.api.get().nonexistingProperty()
1478+
1479+
// then (loading)
1480+
expect(loadingObject).toBeInstanceOf(LoadingStoreValue)
1481+
expect(loadingObject.toJSON()).toEqual('{}')
1482+
1483+
// then (loaded)
1484+
await expect(loadingObject._meta.load).rejects.toThrow("Property 'nonexistingProperty' on resource http://localhost was used like a relation, but no relation with this name was returned by the API (actual return value: undefined)")
1485+
1486+
done()
1487+
})
1488+
1489+
it('throws error when accessing primite property like a relation', async done => {
1490+
// given
1491+
axiosMock.onGet('http://localhost/').reply(200, root.serverResponse)
1492+
1493+
// when
1494+
let loadingObject = null
1495+
loadingObject = vm.api.get().the()
1496+
1497+
// then (loading)
1498+
expect(loadingObject).toBeInstanceOf(LoadingStoreValue)
1499+
expect(loadingObject.toJSON()).toEqual('{}')
1500+
1501+
// then (loaded)
1502+
await expect(loadingObject._meta.load).rejects.toThrow("Property 'the' on resource http://localhost was used like a relation, but no relation with this name was returned by the API (actual return value: \"root\")")
1503+
1504+
done()
1505+
})
14701506
})
14711507
})
14721508
})

0 commit comments

Comments
 (0)