2014-07-16 119 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。