简体   繁体   English

有没有办法计算jasmine describe块中的测试数量?

[英]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. 我试图在describe块中获取测试数量,以确保我们对所有公共接口点进行测试。

Assuming you can actually modify the tests yourself and you're not trying to find them completely from the outside..... 假设您可以自己修改测试,而不是试图从外部完全找到它们.....

Just use this ! 只是用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. 在这里, numOfTests获取块的儿童(测试),显然调用.size它会得到测试的次数。

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. 为了列出更多方法来完成这个,我将发布我自己的方法来访问describe块中的测试计数。

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 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行jasmine测试时,我怎么知道我是否在一个描述块中,在每个块之前还是阻塞? - When running jasmine tests, how can I know if I am in a describe block, beforeEach block or it block? 在Jasmine中为多个相关文件使用describe块 - Using a describe block for multiple related files in Jasmine 茉莉花-如何设置describe块的超时时间? - Jasmine - How to set a timeout for a describe block? 量角器Jasmine描述嵌套在它块内的块 - Protractor Jasmine describe blocks nested within an it block 如何不为茉莉花中的特定Describe()块在BeforeAll中运行某些代码 - How not to run certain codes in BeforeAll for a specific Describe() block in Jasmine 如何抽象和重用茉莉花中的describe()块? - how to abstract and re-use a describe() block in jasmine? 描述块内的 jest.setTimeOut() 是否仅将超时应用于描述块内的测试 - Does jest.setTimeOut() inside a describe block apply the timeout only to tests inside the describe block Jest - 在 describe 块中导入多个测试,重用 beforeEach() 中定义的变量 - Jest - import multiple tests in a describe block, reusing variables defined in beforeEach() 如何获取在描述块中输入的描述? (打字稿) - How to get the description entered in describe block? (typescript) 显示Jasmine运行的测试/期望总数 - Display total number of tests/expectations run by Jasmine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM