Showing posts with label jasmine 3. Show all posts
Showing posts with label jasmine 3. Show all posts

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.