Search code examples
node.jsunit-testinggeddy

Geddy Unit Testing Controller


how you unit test geddy controller? this is an example i want to test.

var assert = require('assert')
    , tests
    , controller = geddy.controller.create('Users');

tests = {
    'test user controller, add new user': function (next) {
        var user = User.create({username: 'hbinduni',
            password: 'MyPassword!',
            confirmPassword: 'MyPassword!',
            familyName: 'binduni',
            givenName: 'binduni',
            email: '[email protected]'});

        //need to unit test controller.add here
        //how to mock req, resp?
        controller.add(req, resp, user);

        assert.equal(out, null);
        next();
    }

};

module.exports = tests;

how can i do unit test on controller method? how to mock request and response?

thank you.


Solution

  • I approached this by creating mock objects for request and response, which may or may not work for you depending how much you rely on the contents of those objects in the first place.

    https://github.com/franksrevenge/geddy-unit-test-utilities