Aug 17, 2021

Unit test on Angular with Jasmine, test case executed randomly

 Problems

If your written unit test is written in an order that has test like:
expect(modalCtrlSpy.dismiss.calls.count()).toBe(1);

The "count()" is accumulated throughout the test cases from the start until the end of a "described" scenario. If test cases get executed without following the order as written test, it fails due to "count()" result get accumulated differently across the test. It can't match the "expected" accumulated result if test run randomly.

Solution

In the karma.conf.js file, add "random: false" under client.jasmine object to prevent test case being executed randomly.



No comments:

Post a Comment

Hey, thank you for spending time leaving some thoughts, that would be really helpful as encouragement for us to write more quality articles! Thank you!