Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Expresso test returning 'Error: Response not completed' on navigation to a static file

Expresso test returning 'Error: Response not completed' on navigation to a static file

Problem

I'm trying to set up a simple project using Node.js and Express with Expresso for testing. I'm using the express.static middleware to serve a static html file (index.html) located in my public directory. This is the code for app.js:

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

// Configuration
app.configure(function() {
    app.use(express.staticCache());
    app.use(express.static(__dirname + '/public'));
    app.use(express.bodyParser());
});

app.listen(3000);

I then wrote a simple test to check for the static file. This is the code for app.test.js:

var app = require('../app')
  , assert = require('assert');

module.exports = {

    'Navigate to root': function() {
        assert.response( 
            app,
            {
                url: '/'
            },
            {
                status: 200,
                headers: { 'Content-Type': 'text/html; charset=utf8'}
            },

            function(res) {
                assert.includes(res.body, 'index');
                assert.ok(res);
            }
        );
    }
};

When I run the test (using expresso or expresso -s) I get the following error:

app.test.js Navigate to root: TypeError: Object # has no method 'listen'
    at Function.response (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:424:16)
    at Test.fn (/home/bill/projects/bidkat.app/test/app.test.js:13:11)
    at Test.runParallel (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:959:10)
    at Test.run (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:924:18)
    at next (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:867:22)
    at runSuite (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:875:6)
    at check (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:814:12)
    at runFile (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:819:6)
    at Array.forEach (native)
    at runFiles (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:796:15)

app.test.js Navigate to root: Error: Response not completed: Navigate to root. 
    at Function.response (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:400:17)
    at Test.fn (/home/bill/projects/bidkat.app/test/app.test.js:13:11)
    at Test.runParallel (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:959:10)
    at Test.run (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:924:18)
    at next (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:867:22)
    at runSuite (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:875:6)
    at check (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:814:12)
    at runFile (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:819:6)
    at Array.forEach (native)
    at runFiles (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:796:15)

I'm obviously doing something silly, but I can't seem to figure out what it is. I thought it might be because my server is already started prior to the test, but it looks like Expresso handles that case. I've also tested a REST endpoint using json to see if it was the static file that was causing the problem but it's giving me the same error.

I'm using Node.js v0.6.6, Express v2.5.4, and Expresso v0.9.2. Thanks!

Problem courtesy of: Bill

Solution

You're not exporting app from your app.js file

Add this to the end

module.exports = app;
Solution courtesy of: fent

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Expresso test returning 'Error: Response not completed' on navigation to a static file

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×