I believe it is considered to be a bad practice to rely on the order in which the (acceptance) tests should be run, but for testing "deeply nested features" (I don't know if there is a standard term for that) it might help to save time (I mean to save the time of repeating the same set of operations before each test; what I have in mind are actually Protractor tests).

So my question is whether there is a standard reliable way to fix the order in which Jasmine tests are perfomed.

3 Answers 3


On Jasmine 3.x, random order is the default behavior.

To run in order file written order, you can specify --random=false or use a seed.

Docs: https://jasmine.github.io/api/3.3/Configuration.html

  • 1
    This is super helpful. I was wondering why my tests are failing and thought random ordering is the reason. Thank you.
    – Arefe
    Commented Aug 18, 2021 at 13:35

You can edit the karma.config file to change the default randomization to false. I got the answer from the following blog: https://www.miguoliang.com/how-to-fix-testing-order-in-angular-with-jasmine.html

  • That link goes to a 404. That's why it's best to provide the info in the post, because links can change. Commented Sep 15, 2023 at 15:24

The following is the right way to do it:

  1. Find jasmine.js in node_modules:

  2. Then find the following line:

       this.sort = this.random ? randomOrder : naturalOrder;

enter image description here

  1. Change it to:

       this.sort = naturalOrder;

enter image description here

Then your unit testing will always run in the order you put them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.