我有一个私有函数,我试图使用Mocha,Chai和Sinon来模拟path.resolve()
。
现在,TypeError: Arguments to path.resolve must be strings
获得var projectDir = path.resolve(__dirname + "../../../");.
。我不知道该如何解决这个问题,因为它是私密的,我无法嘲笑它......并且它没有采取参数函数,所以我无法提供任何东西。
有什么建议吗?
节点脚本:
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);
测试:
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();
});
});