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

Parsing properties from array responses is failing for hasProperty #1312

Closed
Schachte opened this issue Jan 26, 2022 · 3 comments
Closed

Parsing properties from array responses is failing for hasProperty #1312

Schachte opened this issue Jan 26, 2022 · 3 comments

Comments

@Schachte
Copy link

I'm trying to parse an array from my response.

          json:
            input:
              - "input data"
          capture:
            json: "$"
            as: "result"
          expect:
            - statusCode: 200
            - contentType: json
            - hasProperty: "result[0].input"
            - equals:
                - "input data"
                - "{{ result[0].input }}"
      - log: "result is {{ result }}"

The equals block is passing, however, the hasProperty block I can't get working with arrays.
This example in the docs doesn't work properly for me:

expect:
  - hasProperty: 'data[0].id'
@Schachte
Copy link
Author

Looks like I needed [0].input

@hassy
Copy link
Member

hassy commented Jan 26, 2022

Ah yes that is indeed a bit confusing @Schachte! hasProperty runs on the entire response object which lets you access a field directly with [0].input, whereas an equals is a generic way to compare and needs a variable reference. Wondering if we can think of a way to make it clearer 🤔

@Schachte
Copy link
Author

Schachte commented Jan 26, 2022

I think an example would help! Was a little confused on how to get the value correctly. Wasn't sure if my variables could also be used here or not from the capture block, but looks like you answered that one!

Does the expect plugin support things like hasSize or any related type of operations? @hassy

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

2 participants