摩卡测试response.render

时间:2015-02-25 08:34:12

标签: javascript node.js unit-testing mocha

假设我有一个使用response.render呈现页面的函数,我该如何编写一个mocha测试函数来对该页面进行单元测试。

例如:

function getUsers(request, response)
{
 //reading request object
 //getting data from database based on request object
 //finally rendering the page:
   response.render{''users', {partials:{userData:data}
});

//mocha test function (not complete)
describe('users', function(){
    describe('#getUsers()', function(){
        it('It should render users listing page', function(done) {
            //?????
            //?????
        });
    });
});

1 个答案:

答案 0 :(得分:0)

我使用了以下

var httpMocks = require('node-mocks-http');

response = httpMocks.createResponse();

sampleNodeModule.getUsers(request,response);

var responseData = response._getRenderView();