I have the following file that runs when I run node test.js
.
var Jasmine = require('jasmine');
var jasmine = new Jasmine();
var request = require('request');
describe("test", function(){
it("works", function(){
expect(5 + 2).toEqual(4);
});
it("should respond with hello world", function(done){
request('http://localhost:3000/', function(err, res, body){
expect(body).toEqual('hello world');
done();
})
});
})
jasmine.execute();
And this gives me the following output:
Started
F.
Failures:
1) test works
Message:
Expected 7 to equal 4.
Stack:
Error: Expected 7 to equal 4.
at Object.<anonymous>
2 specs, 1 failure
Finished in 0.037 seconds
Obviously one fails, showing the F, and one passes, showing the dot. Can I change this configuration to have it show both the passing and the failing tests?
You'll want to use a custom reporter . I recommend using jasmine-console-reporter , which will give you nicely formatted output that will include all tests that ran (not just the failed ones). Your original script would change to the following:
var Jasmine = require("jasmine");
var jasmine = new Jasmine();
var request = require('request');
// Register a Custom Reporter
const Reporter = require('jasmine-console-reporter');
jasmine.jasmine.getEnv().addReporter(new Reporter());
describe("test", function(){
it("works", function(){
expect(5 + 2).toEqual(4);
});
it("should respond with hello world", function(done){
request('http://localhost:3000/', function(err, res, body){
expect(body).toEqual('hello world');
done();
})
});
})
jasmine.execute();
Note that if you are using the jasmine command line to run the tests (and so Jasmine has exported its helpers into your namespace), your code would be as follows:
const Reporter = require('jasmine-console-reporter');
jasmine.getEnv().addReporter(new Reporter());
I personally find it easiest to use that with Gulp and gulp-jasmine to make the definition clear and in one place, while also allowing me to run build steps prior to the tests:
const gulp = require('gulp');
const jasmine = require('gulp-jasmine');
const Reporter = require('jasmine-console-reporter');
gulp.task('default', function() {
gulp.src('spec/**/*.js')
.pipe(jasmine({
reporter: new Reporter()
}));
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.