vlucas / frisby

Frisby is a REST API testing framework built on Jest that makes testing API endpoints easy, fast, and fun.

Home Page:http://frisbyjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`.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.

Related issues

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.

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.