How to get spec name

2,456 views
Skip to first unread message

CK

unread,
Nov 5, 2015, 4:41:00 PM11/5/15
to Jasmine
How do I get the current spec that is being executed ? I am using jasmine2 framework.

Gregg Van Hove

unread,
Nov 30, 2015, 3:04:08 PM11/30/15
to jasmi...@googlegroups.com
Reporters, including [custom reporters](http://jasmine.github.io/edge/custom_reporter.html), are given metadata about the specs and suites being executed.

-Gregg

On Thu, Nov 5, 2015 at 1:35 PM, CK <chait...@gmail.com> wrote:
How do I get the current spec that is being executed ? I am using jasmine2 framework.

--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+...@googlegroups.com.
To post to this group, send email to jasmi...@googlegroups.com.
Visit this group at http://groups.google.com/group/jasmine-js.
For more options, visit https://groups.google.com/d/optout.

learningp...@gmail.com

unread,
Dec 2, 2015, 6:13:14 PM12/2/15
to Jasmine
Hi Gregg,

As suggested from you I have tried to get all these verbose info by using my own reporter. but when I am running my simple test file, I am getting below output in console.

Test File:

describe('Desc1',function(){
it('Test1',function(){
expect(true).toBe(true);
})
describe('Desc2',function() {
it('Test2', function () {
expect(true).toBe(true);
})
})
it('Test3',function(){
expect(true).toBe(true);
})
afterEach(function(){
var myReporter = {
specDone: function(result) {
console.log('Spec FullName: ' + result.fullName);
console.log('Spec Result: ' + result.status);
},
}
jasmine.getEnv().addReporter(myReporter);
})
})

Output in Console:

.Spec FullName: Desc1 Test1
Spec Result: passed
.Spec FullName: Desc1 Desc2 Test2
Spec Result: passed
Spec FullName: Desc1 Desc2 Test2
Spec Result: passed
.Spec FullName: Desc1 Test3
Spec Result: passed
Spec FullName: Desc1 Test3
Spec Result: passed
Spec FullName: Desc1 Test3
Spec Result: passed

I am not sure why its displaying Test1 once, Test2 Twice and Test3 thrice in editor console. I was expecting only one entry for each Test in console.

Please help me.

Gregg Van Hove

unread,
Dec 2, 2015, 7:31:05 PM12/2/15
to jasmi...@googlegroups.com
You are seeing multiple log lines because the reporter is getting registered in the `afterEach`, which makes a new one for each spec that is run. You want to register the reporter once outside of any specs.

-Gregg

learn protractor

unread,
Dec 11, 2015, 1:59:06 AM12/11/15
to jasmi...@googlegroups.com
Hi Gregg,

Thanks for your help. I made the suggested changes and its working fine now.

I got stuck at one place where my requirement is to get the suite hierarchy.

Desc1
 Desc2
  It('A')
  It('B')
 Desc3
  It('C')
Desc4

I want to show the output results in console with same kind of indentation. I am not sure how to get the suite hierarchy( which is parent is which is child).

Would you please suggest any workaround/solution for my problem.

--
You received this message because you are subscribed to a topic in the Google Groups "Jasmine" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jasmine-js/qqOk6Nh7m4c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jasmine-js+...@googlegroups.com.

Gregg Van Hove

unread,
Dec 11, 2015, 12:14:38 PM12/11/15
to jasmi...@googlegroups.com
Your reporter will receive `suiteStarted` and `suiteDone` events for each suite. Any `suiteStarted` or `specStarted` events received in between the Started and Done for a given spec indicate descendants of that suite. With that information you should be able to get the indentation you want.

Hope this helps. Thanks for using jasmine!

-Gregg
Reply all
Reply to author
Forward
0 new messages