How to test javascript code?

Good evening dear customers and readers!
Faced with such a problem that I can not understand how to test the function of the controller getTracks. Code for this function is as follows:
var Promise = require('bluebird');
 var Errors = require('./errors');
 var pageConditions = require('./sequelize').getPageConditions;

 function getTracks(req, res, next) {

 var conditions = pageConditions(req.params.page, 10);
req.requestedUser.getTracksAndCount(conditions)
 .then(function(result) {
 Res. set('X-Total-Count', result.count);
 Res. set('X-Offset', conditions.offset);
 Res. set('X-Limit', conditions.limit);
Res. json({
 status: 'OK'
 data: result.rows
});
})
 .catch(function(err) {
next(err);
});
 }


The test code below:

var assert = require('assert');
var sinon = require('sinon');
var Promise = require('bluebird');
var appPath = './app';
var mock = require('mock-require');
var Controller = require(appPath + '/users');

describe('User controller', function() {

 describe('method `getTracks`, function() {

 var controller;
 var getPageConditions = sinon.stub();

 beforeEach(function() {
 getPageConditions = sinon.stub();

 mock(appPath + '/helpers/sequelize', {
 getPageConditions: getPageConditions
});
 controller = Controller();
});

 it('response track list if user have tracks by the condition', function() {
 var req = {
 params: {
 page: 'fakeValue'
},
 requestedUser: {
 getTracksAndCount: sinon.stub()
}
};
 var res = {
 set: sinon.spy(),
 json: sinon.spy(),
};
 var next;
 var conditions = {
 offset: 'fakeValueOffset',
 limit: 'fakeValueLimit'
};
 var result = {
 count: 'fakeValueCount',
 rows: 'fakeValueRows'
};

getPageConditions.returns(conditions);
req.requestedUser.getTracksAndCount.returns(Promise.resolve(result));

 controller.getTracks(req, res, next);
assert(getPageConditions.called);
assert(req.requestedUser.getTracksAndCount.calledWith(conditions));
 assert(res.set.calledWith('X-Total-Count', result.count));
 assert(res.set.calledWith('X-Offset', conditions.offset));
 assert(res.set.calledWith('X-Limit', conditions.limit));
});
});
});


Test is performed if zakommentirovat
assert(res.set.calledWith('X-Total-Count', result.count));
 assert(res.set.calledWith('X-Offset', conditions.offset));
 assert(res.set.calledWith('X-Limit', conditions.limit));


Tell me, how is it possible to test that the res has volunteered with these values? I understand that res.set is not working, since
req.requestedUser.getTracksAndCount.returns(Promise.resolve(result));
returns a promise with result - result and all subsequent actions
Res. set('X-Total-Count', result.count);
 Res. set('X-Offset', conditions.offset);
 Res. set('X-Limit', conditions.limit);
Res. json({
 status: 'OK'
 data: result.rows
 });

the functions are not performed
July 9th 19 at 13:12

Find more questions by tags Node.jsTesting software