How do i test my express app with mocha?

前端 未结 5 472
被撕碎了的回忆
被撕碎了的回忆 2020-12-22 18:55

I\'ve just added shouldjs and mocha to my express app for testing, but I\'m wondering how to test my application. I would like to do it like this:

app = requ         


        
5条回答
  •  攒了一身酷
    2020-12-22 19:21

    found an alternative in connect.js tests suites

    They are using supertest to test a connect app without binding the server to any port and without using mock-ups.

    Here is an excerpt from connect's static middleware test suite (using mocha as the test runner and supertest for assertions)

    var connect = require('connect');
    
    var app = connect();
    app.use(connect.static(staticDirPath));
    
    describe('connect.static()', function(){
      it('should serve static files', function(done){
        app.request()
        .get('/todo.txt')
        .expect('contents', done);
      })
    });
    

    This works for express apps as well

提交回复
热议问题