【问题标题】:Geddy Unit Testing ControllerGeddy 单元测试控制器
【发布时间】:2014-07-21 13:34:15
【问题描述】:

你如何对 geddy 控制器进行单元测试?这是我要测试的示例。

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: 'hbinduni@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;

如何对控制器方法进行单元测试?如何模拟请求和响应?

谢谢。

【问题讨论】:

    标签: node.js unit-testing geddy


    【解决方案1】:

    我通过为请求和响应创建模拟对象来解决这个问题,这可能对你有用,也可能对你不起作用,这取决于你对这些对象内容的依赖程度。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-12
      • 2017-06-26
      • 2011-12-01
      • 2014-01-16
      • 1970-01-01
      • 1970-01-01
      • 2018-03-09
      相关资源
      最近更新 更多