`.expect('jsonTypes', 'records.*', {})` does not allow an empty array
kenjiuno opened this issue · comments
I can obtain record list (in JSON) from server.
jsonTypes handler passes if record list is filled with designated items.
However jsonTypes handler seems to disallow empty record list: Expected '*' not found (path 'records.*')
repro/test.js:
const frisby = require('frisby'),
Joi = frisby.Joi;
it('should pass', (done) => {
frisby.fromJSON({ records: [] })
.inspectBody()
.expect('jsonTypes', 'records.*', {
id: Joi.string()
})
.done(done);
});
Run yarn jest repro
FAIL repro/test.js
× should pass (41ms)
● should pass
Expected '*' not found (path 'records.*')
at _.each.segment (node_modules/frisby/src/frisby/utils.js:40:13)
at arrayEach (node_modules/lodash/lodash.js:516:11)
at Function.forEach (node_modules/lodash/lodash.js:9344:14)
at Object.withPath (node_modules/frisby/src/frisby/utils.js:20:5)
at FrisbySpec.jsonTypes (node_modules/frisby/src/frisby/expects.js:112:11)
at response (node_modules/frisby/src/frisby/spec.js:382:23)
at _fetch._fetch.then.response (node_modules/frisby/src/frisby/spec.js:233:34)
console.log node_modules/frisby/src/frisby/spec.js:319
Body: {"records":[]}
console.log node_modules/frisby/src/frisby/spec.js:319
FAILURE Status: 200
JSON: {
"records": []
}
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 4.234s
Ran all test suites matching /repro/i.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I'm happy if test passes in case that record list will be empty.
Just quick idea:
'records.*'
require one or more records, that are all are VALID.'records.*?'
require one or more records, that are all are VALID. Otherwise no record present.