Custom reporter
If you don't like the way the built-in jasmine reporters look, you can always write your own. More details on the Reporter interface can be found in the API docs |
|
A jasmine reporter is just an object with the right functions available. None of the functions here are required when creating a custom reporter, any that are not specified on your reporter will just be ignored. Additionally, in Jasmine 3.0, these functions can all be asynchronous in the same way as the callbacks in your suite.
Either by receiving a |
var myReporter = {
|
jasmineStarted
|
jasmineStarted: function(suiteInfo) {
|
suiteInfo contains a property that tells how many specs have been defined |
console.log('Running suite with '
+ suiteInfo.totalSpecsDefined);
},
|
suiteStarted
|
suiteStarted: function(result) {
|
the result contains some meta data about the suite itself. |
console.log('Suite started: '
+ result.description
+ ' whose full description is: '
+ result.fullName);
},
|
specStarted
|
specStarted: function(result) {
|
the result contains some meta data about the spec itself. |
console.log('Spec started: '
+ result.description
+ ' whose full description is: '
+ result.fullName);
},
|
specDone
While jasmine doesn't require any specific functions, not defining a |
specDone: function(result) {
|
The result here is the same object as in |
console.log('Spec: '
+ result.description
+ ' was '
+ result.status);
for(var i = 0; i < result.failedExpectations.length; i++) {
|
Each |
console.log('Failure: '
+ result.failedExpectations[i].message);
console.log(result.failedExpectations[i].stack);
}
|
The |
console.log(result.passedExpectations.length);
},
|
suiteDone
While jasmine doesn't require any specific functions, not defining a |
suiteDone: function(result) {
|
The result here is the same object as in |
console.log('Suite: '
+ result.description
+ ' was '
+ result.status);
for(var i = 0; i < result.failedExpectations.length; i++) {
|
Each |
console.log('Suite '
+ result.failedExpectations[i].message);
console.log(result.failedExpectations[i].stack);
}
},
|
jasmineDoneWhen the entire suite has finished execution While jasmine doesn't require any specific functions, not defining a |
jasmineDone: function(result) {
console.log('Finished suite: '
+ result.overallStatus);
for(var i = 0; i < result.failedExpectations.length; i++) {
|
Each |
console.log('Global '
+ result.failedExpectations[i].message);
console.log(result.failedExpectations[i].stack);
}
}
};
|
Register the reporter with jasmine |
jasmine.getEnv().addReporter(myReporter);
|
If you write a custom reporter, you should make sure it handles all of the failure modes Jasmine can report on. Note: The way some of the failures are reported has changed in Jasmine 3.0 To help with this, we have a few example Jasmine suites that you can check your reporter against. R
|
|