我仍然非常學習節點,JS,興農,proxyquire等谷歌地理編碼與proxyquire和興農
我有一個使用谷歌的地理編碼模塊(https://github.com/bigmountainideas/google-geocoder)的模塊,我很努力寫一個測試來存根。
這一切都歸結爲我認爲你如何設置它。在time.js我做如下按照谷歌地理編碼文件:
var geocoder = require('google-geocoder');
...
module.exports = function(args, callback) {
var geo = geocoder({ key: some-thing });
geo.find('new york', function(err, response) { ... });
}
我試圖測試如下,但我得到的錯誤:
TypeError: geo.find is not a function
at run (cmdsUser/time.js:x:x)
at Context.<anonymous> (tests/cmdsUser/time-test.js:x:x)
時間test.js:
var time;
var findStub;
before(function() {
findStub = sinon.stub()
time = proxyquire('./../../cmdsUser/time',{ 'google-geocoder': { find: findStub } });
});
describe('Demo test', function() {
it('Test 1', function(done){
findStub.withArgs('gobbledegook').yields(null, { this-is: { an-example: 'invalid' } });
time(['gobbledegook'], function(err, response) {
expect(response).to.equals('No result for gobbledegook');
done();
});
});
});
我有點困惑。非常感謝。