Hey there, I have two pact tests - one is a simple...
# pact-js
d
Hey there, I have two pact tests - one is a simple GET request for all games and the other is a GET request to retrieve a game by ID(query param). For some reason, the pact test with the query param is throwing a
No matching interaction found
Any idea why the pact test for the GET request w/ a query param would be failing when it's seemingly identical to the other working pact test?
Here is a picture of the logs. I'm not really sure how to interpret the missing requests and unexpected requests matching
y
Pretty sure there is a query param you can set in the withRequest https://github.com/pact-foundation/pact-js/blob/51d2ae2e41c8c40e373f264ac7ba633d258604c2/examples/jest/__tests__/index.spec.js#L72 Can't seem to find it in the readme, on mobile and just about to hit the sack
1
But might be enough to help you going. Thanks for sharing the logs
d
Thanks Yousaf! Looks like that's what I needed. Have a goodnight🙂
m
I wonder if we can detect this situation and complain, letting users know the query string should be in the
query
property? 🤔
👌 1
👍 1
t
absolutely.
?
is not allowed in paths, so it's a trivial check
y
that would be lovely, but if we could detect that, we could probably just stick in it the query prop itself, so idk. first start is get it documented on the readme, as it isn't at the mo.
t
I don't think we should rewrite the path for them - the property is for the path, not the query
y
yeah thats gnarly I agree, it depends on how helpful you want be, but that is too opaque. The fact it isn't in the pact-js docs means people don't know that query prop exist unless they look at code or other pact docs, which is why they are putting query in the string in the first place
👍 1
and people see query params in strings in their web browser so much confuse
Glad it was a the right answer for Damien, as I have some outstanding issues around query strings in javascript land, that may be resolved now, from back in the day
and we can sort out a nice little snag in the docs that should help some folks for the future, and then get the nice DX stuff in the logs. 💛
t
It's hard to be too helpful with query strings because they're not clearly defined. The W3C recommends using
application/x-www-form-urlencoded
, but that recommendation is not required by any standard. An important difference is how spaces work - spaces in
application/x-www-form-urlencoded
are encoded as
+
, but in general URLs, they're URL encoded to
%20
. Also, there's no standard at all for repeat parameters - some implementations will do
key=val1&key=val2
, some will do
key[]=val1&key[]=val2
, and some will do
key[1]=val1&key[2]=val2
. I think
key[]
is what pact does (and the most common interpretation), but I don't actually know. The W3C recommendation is just to treat it as a list of pairs, and doesn't say that the keys need to be unique.
y
Really good information there Tim! thank you for that. That is indeed going to be awkward, in trying to be proactively helpful. I might use some of that, and w3c's recs, and test out a few combos so we can offer at some guidance on what Pact supports and doesn't support. As unclear as it might be, we can at least provide guidance on what we are able to cover, by ways of tests, my favourite kind of documentation.
😂 1