Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8489693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:53:56+00:00 2026-06-10T21:53:56+00:00

I can’t seem to get the following integration test to pass in an express

  • 0

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

should  = require('should')
request = require('supertest')
app     = require('../../app')

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')
          .end (err, res) ->
            res.text.should.include('logged in')
            done()

Relevant application code

app.post '/sessions', (req, res) ->
  req.flash 'info', "You are now logged in as #{req.body.user}"
  res.redirect '/login'

Failure

1) authentication POST /sessions success displays a flash:
   AssertionError: expected 'Moved Temporarily. Redirecting to //127.0.0.1:3456/login' to include 'logged in'

Obviously, the application code doesn’t do anything useful. I’m just trying to get the test to pass.

Putting the expectation (res.text.should.include('logged in')) outside the end function and inside the expect function yields the same results. I’ve also tried a variation of the function calls, for example removing the .type('form') call, and using .send(user: 'username', password: 'password') instead of the two .field() calls.

If it means anything, sending a curl POST request to the the app when it’s running locally yields the same output (Moved Temporarily. Redirecting to //127.0.0.1:3456/login)

I have a feeling this is a trivial error. Possibly something I’m forgetting in the application code or the test code.

Any suggestions?

EDIT 1: It’s also worth noting that when clicking the submit button in the browser I get the expected results (a flash message).

EDIT 2: Further investigation shows the output of any redirect results in the Moved Temporarily. Redirecting to ... response body. This makes me wonder if there is a problem in the way I’m exporting the app in app.js.

var express = require('express')
var app = express();

module.exports = app;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:53:58+00:00Added an answer on June 10, 2026 at 9:53 pm

    For anyone who comes across this page, the answer to this question is pretty simple. The Moved Temporarily. response body is what is returned from supertest. See the issue for more details.

    To summarize, I ended up doing something like this.

    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')
              .end (err, res) ->
                res.header['location'].should.include('/home')
                done()
    

    Just check that the response header location is what you expect it to be. Testing for flash messages and view specific integration tests should be done using another method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I change the field public virtual ClassOne ClassOne { get; set; } to
Can I authenticate with just Google account username and password instead of using OAuth?
Can any one tell, how to get the result of LINQ query contains group
Can someone thoroughly explain the last line of the following code: def myMethod(self): #
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Can someone please explain to me why the output from the following code is
Can I be notified of the following events for an Activity: screenSizeWillChange screenSizeDidChange I
Can I have a project that has some parts written in c and other
Can MOSS integrate and get user profiles from multiple Active Directory and/or LDAP stores?
Can anyone tell me what i am doing wrong? I am trying to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.