我想知道,是否有可能获得测试的完整嵌套描述路径?
假设:
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 :(得分:5)
jasmine.Suite 和 jasmine.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>
注意:此答案现在有点过时,并在示例中使用了Jasmine 1.3.1。
答案 1 :(得分:-1)
当你进入描述回调函数时,这被设置为&#34;套件&#34;具有套件描述的对象(您传递给描述的文本)和父套件的属性。
以下示例获取描述嵌套描述调用的串联,我不确定如何访问&#34; it&#34;的描述。但这会让你在那里分道扬。
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(){
});
});
});