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?
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.
set "random" to false in jasmine.json
The file should be added in spec/support/jasmine.json
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With