Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is jasmine supposed to execute specs in the order they are declared or in a random order?

Tags:

un-comment the last spec. All hell breaks loose... why?

describe('test', function() {   var index = 1;    it('test 1', function() {     expect(index).toBe(1);     index++;   });    it('test 2', function() {     expect(index).toBe(2);     index++;   });    it('test 3', function() {     expect(index).toBe(3);     index++;   });    it('test 4', function() {     expect(index).toBe(4);     index++;   });    it('test 5', function() {     expect(index).toBe(5);     index++;   });    it('test 6', function() {     expect(index).toBe(6);     index++;   });    it('test 7', function() {     expect(index).toBe(7);     index++;   });    it('test 8', function() {     expect(index).toBe(8);     index++;   });    it('test 9', function() {     expect(index).toBe(9);     index++;   });    it('test 10', function() {     expect(index).toBe(10);     index++;   });    // it('test 11', function() {   //   expect(index).toBe(11);   //   index++;   // });  }); 

thanks to @PWKad for pointing out this happens when there are more than 10 tests.

like image 300
Jeremy Danyow Avatar asked May 05 '15 11:05

Jeremy Danyow


People also ask

Which matter is used in Jasmine to check whether the result is equal to true or false?

Perhaps the simplest matcher in Jasmine is toEqual . It simply checks if two things are equal (and not necessarily the same exact object, as you'll see in Chapter 5).

Which function in Jasmine executes a function before each test?

For initializing and cleaning your specs, Jasmine provides two global functions, beforeEach() and afterEach() : The beforeEach function is called once before each spec in the suite where it is called. The afterEach function is called once after each spec in the suite where it's called.

Which of the following specifies where Jasmine looks for test files?

Jasmine does not require the project to have a specific directory layout, but it does use a configuration file to specify where to find tests. The default, conventional project structure created by “jasmine init” puts all Jasmine code into a “spec” directory, which contains “*spec.

What is done () in Jasmine?

Using the done() Method in Your Jasmine-driven Asynchronous JavaScript Tests. Jasmine. Async is an add-on library for Jasmine that provides additional functionality to do asynchronous testing. Modeled after Mocha's async test support, it brings the done() function to the Jasmine unit testing environment.


1 Answers

Yes, Jasmine executes the specs (it) in order. There was an issue from 2.3.0 to 2.3.3 with more than 10 specs. I hit the same issue in 2.3.3, the issue is fixed in 2.3.4.

https://github.com/jasmine/jasmine/issues/850

I just used 2.3.4 in place of 2.3.3 and my 15 tests finally passed.

like image 93
user1559679 Avatar answered Nov 03 '22 23:11

user1559679