-
Notifications
You must be signed in to change notification settings - Fork 56
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
Matcher includes is not working in expectJsonSnapshot #100
Comments
Hi, I was reviewing the issue and I have a propose for solution.
What do you thinks about? |
The matchers are initially designed to support contract testing. Need to evaluate on how it effects the matching capabilities at flow server if we start supporting callback functions. |
Yes, It's true, is necessary evaluate the impact. Another solution could be passing the functions as string in to include(), and use eval() o new Function()() for evaluate in to _validateJsonSnapshot(response) , for example: ...
"id": includes('return response.body.id')
...
// In _validateJasonSnapshot(response)
// Previews validations of return in string
value = new Function(value)(response)
...
const current_rules = jmv.getMatchingRules(value, '$.body') |
I add a draft PR for review the second solutions. #213 |
I close Pull Request , comment in the PR! #213 |
@olcortesb Thank you for taking time to fix this issue. The easiest resolution would be making the strict comparison configurable while validating json snapshots. const strict = false;
const errors = jmv.validate(actual, expected, all_rules, '$.body', strict); User needs to be cautious while disabling strict comparison. May be we can pass the expectJsonSnapshot(matchers, strict?);
expectJsonSnapshot(name, matchers, strict?); |
OK, Interesting, I take your recommendation with strict comparison configurable and prepare a Pull Request! thanks |
This is fixed pactumjs/pactum-matchers#26 |
Discussed in #98
Originally posted by captaincc423 December 1, 2021
I'm trying to get some matchers to work in expectJsonSnapshot and I'm running into a few problems:
"id": includes(response.body.id)
and it's not working. It always says it doesn't match.Am I misusing these matchers?
The text was updated successfully, but these errors were encountered: