Testing requests that redirect with mocha/supertest in node

后端 未结 4 637
北恋
北恋 2021-02-01 02:35

I can\'t seem to get the following integration test to pass in an express project using mocha, supertest, and should (and coffeescript).


The test<

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-01 02:56

    There is built-in assertion for this in supertest:

    should  = require('should')
    request = require('supertest')
    app     = require('../../app')
    
    describe 'authentication', ->
      describe 'POST /sessions', ->
        describe 'success', ->
          it 'redirects to the right path', (done) ->
            request(app)
              .post('/sessions')
              .send(user: 'username', password: 'password')
              .expect(302)
              .expect('Location', '/home')
              .end(done)
    

提交回复
热议问题