2014-07-16 51 views
3

我在想,是否有可能获得测试的完整嵌套描述路径?Jasmine Testing获取完整描述的名称/它的

考虑:

describe('Smoke Testing - Ensuring all pages are rendering correctly and free of JS errors', function() { 
    describe('app', function() { 
    describe('app.home', function() { 
     it('should render this page correctly', function (done) { 
     //name here should be: Smoke Testing - Ensuring all pages are rendering correctly and free of JS errors app app.home should render this page correctly 
     done() 
     }) 
    }) 

    describe('app.dashboard', function() { 
     describe('app.dashboard.foobar', function() { 
     it('should render this page correctly', function (done) { 
     //name here should be: Smoke Testing - Ensuring all pages are rendering correctly and free of JS errors app app.dashboard app.dashboard.foobar should render this page correctly  
      done() 
     }) 
     }) 
    }) 

    }) 

}) 

回答

0

当你将其设置到具有套件的描述(你传递描述文本),并为一个属性“套件”对象的描述回调函数内父母套件。

下面的示例获取描述嵌套描述调用的连接,我不确定如何访问“it”的描述。但是这会让你分开。

var getFullDesc = function(suite){ 
    var desc = ""; 
    while(suite.parentSuite){ 
     desc = suite.description + " " + desc; 
     suite = suite.parentSuite; 
    } 

    return desc; 
} 

describe('Outer describe', function(){ 
    describe('Inner describe', function(){ 
     console.log(getFullDesc(this)); 
     it('some test', function(){ 

     }); 
    }); 
}); 
6

两个jasmine.Suitejasmine.Spec有方法getFullName()。作品如你所期望:

describe("A spec within suite", function() { 
 
    it("has a full name", function() { 
 
    expect(this.getFullName()).toBe('A spec within suite has a full name.');  
 
    }); 
 
    
 
    it("also knows parent suite name", function() { 
 
    expect(this.suite.getFullName()).toBe('A spec within suite');  
 
    }); 
 
});
<script src="http://searls.github.io/jasmine-all/jasmine-all-min.js"></script>

注意:现在这个答案是有点过时和示例使用茉莉花1.3.1。