Testing requests that redirect with mocha/supertest in node

后端 未结 4 643
北恋
北恋 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:48

    describe 'authentication', ->
      describe 'POST /sessions', ->
        describe 'success', (done) ->
          it 'displays a flash', (done) ->
            request(app)
              .post('/sessions')
              .type('form')
              .field('user', 'username')
              .field('password', 'password')
              .redirects(1)
              .end (err, res) ->
                res.text.should.include('logged in')
                done()
    

    The redirects() will follow the redirect so you can do your usual view tests.

提交回复
热议问题