custom_reporter.js |
|
---|---|
If you don’t like the way the built-in jasmine reporters look, you can always write your own. |
|
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. |
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);
}
},
|
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++) {
|
Any |
console.log('AfterAll ' + result.failedExpectations[i].message);
console.log(result.failedExpectations[i].stack);
}
},
|
jasmineDoneWhen the entire suite has finished execution |
jasmineDone: function() {
console.log('Finished suite');
}
};
|
Register the reporter with jasmine |
jasmine.getEnv().addReporter(myReporter);
|
If you look at the console output for this page, you should see the output from this reporter |
describe('Top Level suite', function() {
it('spec', function() {
expect(1).toBe(1);
});
describe('Nested suite', function() {
it('nested spec', function() {
expect(true).toBe(true);
});
});
});
|