angularjasminekarma-jasminekarma-runner

Can I run Karma Tests with a specified seed?


I'm working in an Angular Project that is tested with Karma/Jasmine. Angular tests, by default, run in a randomized order, which may result a test failing if ran in a certain order.

I've noticed that in my browser runner, it displays the randomized seed that the tests were ran with.
When running tests, can I specify this seed, so that I can test the same order more than once? (And so I can pass this seed to others to show in what order their tests fail).


Solution

  • As Mikhail Istomin's blog post here points out (under the section titled "The Seed") you can take the seed value that failed and add it to the jasmine section of your karma.config.js file like this:

    // karma.config.js
    module.exports = function (config) {
      config.set({
        // ... other settings
        client: {
          jasmine: {
            random: true,
            seed: '05217'
          },
        },
      });
    };