vlucas / frisby

Frisby is a REST API testing framework built on Jest that makes testing API endpoints easy, fast, and fun.
http://frisbyjs.com
1.53k stars 201 forks source link

`.expect('jsonTypes', 'records.*', {})` does not allow an empty array #529

Closed kenjiuno closed 3 years ago

kenjiuno commented 5 years ago

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.

H1Gdev commented 5 years ago

Related issues

kenjiuno commented 5 years ago

Just quick idea:

koooge commented 3 years ago

Hi, sorry you ran into this issue, and thank you for the report. It looks like this has been already reported in #462, so to consolidate the discussion and efforts, I'm going to close this issue in preference to the previous issue.