function authenticateOk(username, password) { var user = findByUsername(username); return (user != null && user.password === password);}
function findByUsername(username) { return null;}
module.exports.authenticateOk = authenticateOk;module.exports.findByUsername = findByUsername;
var sinon = require('sinon');var assert = require('assert');var users = require('./users');
var user = { username: 'uudashr', password: 'uudashr123'};
var findByUsernameStub = sinon.stub(users, 'findByUsername');findByUsernameStub.returns(user);
var returnedUser = users.findByUsername(user.username);assert(returnedUser != null, '#findByUsername should return non null user');
var result = users.authenticateOk(user.username, user.password);assert(result, '#authenticateOk should return true');
findByUsernameStub.restore();
...
function authenticateOk(username, password) { var user = module.exports.findByUsername(username); return (user != null && user.password === password);}...--
You received this message because you are subscribed to the Google Groups "Sinon.JS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sinonjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
module.exports = { authenticateOk: function(username, password) { var user = this.findByUsername(username); return (user != null && user.password === password); }, findByUsername: function(username) { return null; }};var findByUsername = function(username) { return null;};
function authenticateOk(username, password) { var user = this.findByUsername(username); return (user != null && user.password === password);}
module.exports.authenticateOk = authenticateOk;module.exports.findByUsername = findByUsername;