-
-
Notifications
You must be signed in to change notification settings - Fork 343
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
Problems with Mock Server when running Pact with Jest #1060
Comments
Thanks for the detailed report and repro - much appreciated! I'm going to remove the
This makes me think there is a proxy of sorts intercepting requests - probably as part of the Angular setup. I'm not an Angular developer, but I know it does funky things with the HTTP clients in the test bed (or whatever they call it), so this is where I'd be investigating. Alternatively, there is some promise issue where the promises are firing out of order. |
Can you share the test that generates this problem? |
I think it's this one Tim: https://github.com/subodhgodbole/angular-pact/blob/main/src/app/services/user.service.pact.spec.ts My guess is that it's something to do with Angular proxying/interfering with HTTP requests. It could probably be shown to be the issue by using a different HTTP client (e.g. axios). If it works, you are likely to believe it's something to do with the Angular setup. If it doesn't work, then it would be a bit more digging, but one would also have to suspect some other deeper dependency/configuration is at work (because we have many working examples) |
That test isn't right. It's not handling the promise from
should be (at least):
|
Yep. This one is entirely unhandled promises at fault - the problem is that the I don't know what you're supposed to do idomatically in Angular. But, this updated test works:
^ This means that you need to make sure that the |
Thanks @TimothyJones. You pointed it right, test is finishing early and not waiting for Exactly for this async behavior Jest offers
I have used this |
No, that is not right. In that example, Here is the sequence of events:
In your example, you have written this:
In general, it's better to use the promise form instead of the callback form, as it avoids these kind of issues (I think using |
Nope! That does not appear to be the case as per code. |
You are not using done correctly. See my earlier messages, and try the corrected code I gave you. |
I have pushed one more commit to my Git Repo. In this commit -
Looks like for Pact Tests I believe we can close this issue as original issue is resolved. |
I'm glad you've got it working. However, I think you still haven't understood what I was saying above. Pact is compatible with
As you can see, it's more wordy. If you prefer this way, then you could use this style instead. Calling As an aside, this is a really good example of why |
A second aside - I looked at your other, non-pact test, and you are not using To fix this, I would recommend moving that This isn't jest support though, so I'll leave correcting the rest of the uses of |
Thanks!! But IMO, main point of comparison was that -
Like I said this thread can be closed, as main problem with witting Pact Tests is resolved by using Thanks. |
I'm not sure whether this Issue should be closed. The same happens when
|
Hi @pdeszynski I think that is a separate issue from the one initially reported here. Could you please open a new ticket with a reproducible example (the issue template should have this info) and we can look into it separately? |
@pdeszynski are you using node 19? If yes, see #1066 for further information. |
Software versions
Issue Checklist
attached a log file showing the complete request/response cycleExpected Behavior
Mock server should start and respond as per Interactions defined.
Actual Behavior and Steps to reproduce
I am trying to use Pact in my Angular 13 workspace with Jest for writing contract tests.
I am using latest version of Pact which is v10.4.1.
However, I am running into problems related to Mock Server.
It seems that Mock Server is not receiving any requests.
I have added multiple debug logs to check which URL is used by Angular's HttpClient and it appears to point correctly to Mock Server's dynamic URL. See this -
From above -
http://127.0.0.1:50118
./users/1
.http://127.0.0.1:50118/users/1
.But still it's not working.
Also, I am not sure why Mock Server Id is coming out as "undefined".
Error I get is as below -
May be I am missing something very trivial/basic, I would really appreciate if you have any clue / suggestion on what might be wrong in my project?
I have uploaded my Angular project to GitHub here, where this is reproducible. (After cloning, command to run is
npm run test:pact
).PS: I raised this on stackoverflow few days back. Also raising it here, in anticipation to get resolution faster.
The text was updated successfully, but these errors were encountered: