简体   繁体   中英

Is there a way to get the count for the number of tests in a jasmine describe block?

Is there any way to get the number of tests in a jasmine describe block? I am trying to get the number of tests in a describe block to make sure we have tests for all the pubic interface points.

Assuming you can actually modify the tests yourself and you're not trying to find them completely from the outside.....

Just use this !

describe("Testing Suite", function(){

   var numOfTests = this.children.size;
   console.log(numOfTests);

    it("should do something", function(){
       //do something
    })

    it("should do something", function(){
      //do something else
    })
})

Here, numOfTests gets the children(tests) of the block, and obviously calling .size of it will get the number of tests.

For the sake of listing more ways to accomplish this I will post my own method for accessing the count of the tests inside the describe block.

var publicAPI = describe('Public  Interface', function () {

    /* Methods */
    it('should expose/define a initialize method', function () {
        expect(controller.initialize).toBeDefined();
    });
});

console.log(publicAPI.specs_.length); //this is the count 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM