Geddy Unit Testing Controller

25 views
Skip to first unread message

Heriyanto Binduni

unread,
Jul 21, 2014, 1:48:49 PM7/21/14
to ged...@googlegroups.com
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: 'hbin...@email.com'});

        //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.


Matthew Eernisse

unread,
Jul 22, 2014, 3:13:24 AM7/22/14
to ged...@googlegroups.com
That should give you some ideas how to exercise your controller code.

Hope that helps.


Best,

Matthew


--
The official community discussion group.
website: geddyjs.org, source: https://github.com/mde/geddy, group: https://groups.google.com/d/forum/geddyjs?hl=en
---
You received this message because you are subscribed to the Google Groups "GeddyJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geddyjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Heriyanto Binduni

unread,
Jul 22, 2014, 3:55:01 PM7/22/14
to ged...@googlegroups.com
thank you matthew for your reply. i have look into that before but still i didn't understand. can you give more example please?

Matthew Eernisse

unread,
Jul 23, 2014, 3:52:44 AM7/23/14
to ged...@googlegroups.com
Although the BaseController tests give you an example of how to import your constructor for the controller and instantiate it.

Basically the idea is to instantiate a controller, and override the `output` method, which is the low-level controller method which actually writes out the response content. You can override `output` with a function that simply checks that the output is what you expect after running certain controller methods.

Hope that helps.


Matthew
Reply all
Reply to author
Forward
0 new messages