Hey <@UELMFD9PG> I just noticed some weird behavi...
# pact-js
d
Hey @Yousaf Nabi (pactflow.io) I just noticed some weird behavior when running the pact tests. The Pact test will pass and then when I run the pact test again it will randomly fail all of a sudden? Even though I didn't change anything. I kept running the Pact test and it took me 5 tries before the pact test passed again. Heres a link to the Github repo with the latest code - https://github.com/damianavid/angular-pact
y
I wont have time to look at this so you are on your on for now buddy, but if I get some this week, i'll take a look. I would revert back to that commit of the PR as there are some additional changes there
d
No worries. I should be able to keep going as the test will occasionally show a success. I just wanted to bring it to your attention since even reverting back to your PR it still shows the same behavior. If I continue to run the pact test it won't pass 100% of the time. It almost seems random. e.g. one fail one pass, four fails, one pass, etc, etc.
m
Sounds like promises or a misconfiguration.
d
Hey Matt, It's an observable. This ended up being a mistake on my end. Jest will throw false positives if you don't handle async tests correctly by adding done() at the end of the subscribe block. After fixing my test they pass 100% of the time now.
👍 1
Adding this here for anyone else who may run into issues with async tests and need a reference.
Copy code
it('returns Welcome to api!', (done) => {
            service.helloWorld(provider.mockService.baseUrl).subscribe((res) => {  
            expect(res).toEqual({
                message: 'Welcome to api!'
            })
            done();
            });
        })
y
60% anchorman
🤣 1
😅 Thanks for the update @damian 🙌
Would love to add an example to pact-js when you have it all sorted e2e 🙂
1
m
Hey Matt, It’s an observable. This ended up being a mistake on my end. Jest will throw false positives if you don’t handle async tests correctly by adding done() at the end of the subscribe block. After fixing my test they pass 100% of the time now.
right, same point basically - it’s an async operation and Jest needs to know to wait for it