lundi 23 février 2015

How do I mock path.resolve() when it's private?

I have a private function that I am trying to mock path.resolve() using Mocha, Chai, and Sinon.


Right now, I get TypeError: Arguments to path.resolve must be strings for var projectDir = path.resolve(__dirname + "../../../");.. I am not sure how to go about this because it's private I can't mock it...and it doesn't take argument functions so I can't feed it anything.


Any suggestions?


Node script:



function constructDestwCallBack(absSrcFile, callback) {
console.log(path.resolve(__dirname + "../../../"))
var projectDir = path.resolve(__dirname + "../../../");
...

function foo(callback) {
var destinationFile;
errorCheckArg(arguments);
return through2.obj(function(file, enc, next) {
destinationFile = constructDestwCallBack(absSrcFile, callback);




Test:



describe('gulp-foo', function() {
var fakeFile, pspy;

beforeEach(function() {
mock({
'/apple/pear/foo.less': mock.file({
content: 'nothing',
mtime: new Date(Date.now())
})
});
fakeFile = new File({
contents: new Buffer('/apple/pear/foo.less')
});

});
afterEach(mock.restore);


describe('get files', function() {

it('should do something', function(done) {
var path = { resolve: function() { return "ssss"} };
sinon.spy(path, "resolve");


var bar = function(dest) { return dest};
stream = foo(bar);
done();
});
});

Aucun commentaire:

Enregistrer un commentaire