Replies: 2 comments 5 replies
-
Can you please elaborate perhaps with code examples of what you mean? I've not seen this problem before, at least not framed the way you described. Normally yes, you'd await the promise. |
Beta Was this translation helpful? Give feedback.
-
So it may framed this way, because most unit testing frameworks provide a mechanism for setting a timeout, a set of maintainers built jest-pact and mocha-pact as wrappers around pact-js for that very function https://github.com/pact-foundation/jest-pact If you have synchronous code and don't want to introduce async/await, you can use callbacks.
You may need to refactor code in order to make it testable, which is why testability of code is considered a good measure of code quality |
Beta Was this translation helpful? Give feedback.
-
So my guess is this is a reoccurring problem.
When you use any testing library for your WEB component tests you will have PactJS running on some port and waiting for interactions but the .verify() is going to be called from your unit test.
What is the best way to make sure that by the time you call .verify() all the expected network requests are already made (and have reached Pact)?
The best solution I could come up with so far is to return a promise from the component and wait on that in the test. This sometimes requires you to change your component code, what is imho not ideal. Maybe there is a wait with a timeout option in Pact? I could not find it in the docs. Not sure what waitForServerReady does?
Why this is relevant? Ofc you can make this sort of work, by adding a sleep or moving the verification into afterEach or similar. Regardless what you will get are flaky tests, that tend to break on different environments like CI/CD.
Beta Was this translation helpful? Give feedback.
All reactions