Use jasmine to test Express.js

前端 未结 6 674
庸人自扰
庸人自扰 2021-02-04 01:06

I am learning Node.js and Express framework. I am a big fan of jasmine. So I want to use jasmine whenever I can, however, I can\'t find a good way testing Express with jasmine.

6条回答
  •  没有蜡笔的小新
    2021-02-04 01:23

    Maybe you could try supertest with mocha.

    Here's a simple example :

    var request = require('supertest')
      , express = require('express');
    
    var app = express();
    
    app.get('/user', function(req, res){
      res.send(200, { name: 'toto' });
    });
    
    
    describe('GET /user', function(){
      it('should respond with json', function(done){
        request(app)
          .get('/user')
          .set('Accept', 'application/json')
          .expect('Content-Type', 'json')
          .expect(200, done);
      })
    })
    

提交回复
热议问题