Reputation: 323
I'm using Karma/Jasmine to run many spec files. My tests make use of some global functions. Some tests mock up the global functions, which other tests depend on. Since the tests are being run asynchronously, some tests fail since the expected behaviour of the global functions is changed by other tests.
Is there a way to run the tests sequentially?
Upvotes: 12
Views: 13124
Reputation: 12397
The flag --random=false
will run the tests sequentially. I have the script to achieve that:
"test": "ENV=dev && db-migrate --env dev up && jasmine-ts --random=false && db-migrate reset --env dev",
Upvotes: 1
Reputation: 153
set "random" to false in jasmine.json
The file should be added in spec/support/jasmine.json
Upvotes: 9
Reputation: 587
I don't think that async tests will run two tests at the exact same time. This side effect is most likely happening because you are not reseting your global functions after the individual test ends. If you don't restore the global function after each test and the next test that runs (which could be any individual test in your suite) could fail if it relies on the same function.
For example (using sinon)
describe("A suite", function() {
beforeEach(function() {
sinon.stub(someGlobal, 'someFunc')
});
afterEach(function() {
someGlobal.sumFunc.restore()
})
it("uses global function", function() {
...
});
});
*You can, however, set random to false in your jasmine config to run your specs in order - https://jasmine.github.io/setup/nodejs.html.
Upvotes: 5