Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kenjiuno opened this issue Jun 12, 2019 · 3 comments
Closed

Comments

@kenjiuno
Copy link

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.

@kenjiuno
Copy link
Author

kenjiuno commented Jul 9, 2019

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.

@kenjiuno kenjiuno closed this as completed Jul 9, 2019
@kenjiuno kenjiuno reopened this Jul 9, 2019
@koooge
Copy link
Collaborator

koooge commented May 24, 2021

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.

@koooge koooge closed this as completed May 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants