Closed jjdd12 closed 4 years ago
You need to wait on the promise that addInteraction
returns. Change:
beforeEach(() => {
provider.addInteraction({
for:
beforeEach(() => // note the implicit return instead of open brace
provider.addInteraction({
alternatively you can use async
/await
. It's a matter of preference.
Note that your it
function will have the same problem - the function will return before the expect
is triggered. Either return a promise or await
it to make sure that the test is asserting correctly.
I think I'll add a note to the readme to make this clearer.
(another source of brittle tests is running the tests in parallel - this occasionally causes failures when writing pacts. Make sure you're invoking jest with --runInBand
)
I'll leave this open in case this doesn't fix your issue. Feel free to close it if it does.
I think adding the note to the readme as you mentioned will be useful, thanks for your help
You're welcome! Glad it worked out 👍
I am facing a race condition issue. Sometimes the test passes, but more often than not it fails, since, the test runs before the provider adds the interaction, I figured out a few workarounds, however since my test looks a lot like the examples in the Readme, I'd like to know if I am doing something wrong, or if this is expected behavior here is my test: