You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there. 😸 .expect('jsonTypes', '*', {}) does not allow an empty array. But API which returns array of objects usually returns [] even when the array has no object.
So, I think .expect('jsonTypes', '*', {}) should allow [].
what do you think about this?
> jest
FAIL ./hoge.spec.js
✕ should pass (25ms)
● should pass
Expected '*' not found (path '*')
at _.each.segment (node_modules/frisby/src/frisby/utils.js:48:13)
at arrayEach (node_modules/lodash/lodash.js:508:11)
at Function.forEach (node_modules/lodash/lodash.js:9334:14)
at Object.withPath (node_modules/frisby/src/frisby/utils.js:16:5)
at FrisbySpec.jsonTypes (node_modules/frisby/src/frisby/expects.js:108:11)
at response (node_modules/frisby/src/frisby/spec.js:376:23)
at _fetch._fetch.then.response (node_modules/frisby/src/frisby/spec.js:217:34)
console.log node_modules/frisby/src/frisby/spec.js:326
Body: []
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
The error message could be improved, but technically the test is not wrong. There are no objects that exist when you are trying to run assertions on them.
Also on a side note: It is usually not a good idea to return an array as the root element in an API response, because you can never change it or add any other keys once it is done. I always return an object with a data key instead, like this: { data: [] }. It is much more flexible (I have added a meta key with request dates and info for caching, a links key with pagination URLs for next/prev, etc.).
Hi there. 😸
.expect('jsonTypes', '*', {})
does not allow an empty array. But API which returns array of objects usually returns[]
even when the array has no object.So, I think
.expect('jsonTypes', '*', {})
should allow[]
.what do you think about this?
test code
fyi) my workaround
The text was updated successfully, but these errors were encountered: