Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple execution of similar routes #44

Closed
jpgarcia opened this issue Dec 16, 2012 · 2 comments
Closed

multiple execution of similar routes #44

jpgarcia opened this issue Dec 16, 2012 · 2 comments

Comments

@jpgarcia
Copy link

Hi guys, I'm trying to test two routes that are pretty much the same except that one of them is more specific as the latest url segment is a hardcoded value (edit) while the other has a parameter (:slug).

The issue I'm experiencing is that when the request is executed it will call both routes (edit, show) causing my mock never() expectation never pass :(

Am I doing something wrong? I dont't get why both routes are executing if one of them is more specific...

This is the test:

var request = require('supertest')
    , express = require('express')


describe('routes', function() {
    it('should call only edit', function(done) {
        var usersController = require('./users-controller');
        var sandbox = require('sinon').sandbox.create();
        var mockController = sandbox.mock(usersController);

        mockController.expects('edit').yields(null).once();
        mockController.expects('show').never();

        var app = express();

        app.get('/users/:id/edit', usersController.edit);
        app.get('/users/:id/:slug', usersController.show);

        request(app)
          .get('/users/123/edit')
          .end(function(err, res){
            if (err) throw err;
            mockController.verify();
            done();
          });
    });
});

and here is the users-controlle.js I'm mocking above:

exports.edit = function(req, res, next) {
    res.send('edit');
}

exports.show = function(req, res, next) {
    res.send('show');
}
@tj
Copy link
Contributor

tj commented Dec 22, 2012

im not even looking at mock stuff sorry, that's not my lib I have no clue what it's doing internally

@gjohnson
Copy link
Contributor

this is a mocking issue not a supertest issue.... Pro-tip though: test your code, not fake (mocked) code. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants