我是javascript + node beginner,也是异步编程风格的新手。我对Ruby和Rails很满意,现在正在尝试自学节点。
我正在开发一个节点应用程序,我需要从Facebook获取数据,我正在使用'facebook-api'节点包。
我正在使用BDD方法(这里也是新手,从未在ruby中使用过很多的rspec)和mocha + should.js。
以下是我编写的一些早期代码:
LIB / facebook_adapter.js
var raw = require('facebook-api').raw;
function getFacebookData(facebookpage,callback)
{
raw("GET",facebookpage,[],function(error,data){
if (error)
{
conosle.log(error);
}
else
{
var facebook_data = {};
facebook_data.likes = data.likes;
facebook_data.talking_about = data.talking_about;
}
callback(facebook_data);
});
}
module.exports = {
'getFacebookData' : getFacebookData
};
测试/ facebook.test.js
'use strict';
var assert = require('assert')
,should = require('should')
,facebook_adapter = require('../lib/facebook_adapter');
describe('FacebookAdapter',function(){
it('should fetch the like and followcount for a brand name from Graph API',function(done){
facebook_adapter.getFacebookData('Edelman', function(facebook_data){
for ( var prop in facebook_data)
{
console.log('meoww');
facebook_data[prop].should.be.a('number');
}
done();
});
});
});
要执行mocha测试,我在express应用程序的根目录中有一个makefile。以下是内容:
test:
@./node_modules/.bin/mocha -u tdd
.PHONY: test
现在,在执行测试时,我总是最终得到错误:
․․․meoww
meoww
․․
✖ 2 of 4 tests failed:
1) FacebookAdapter should fetch the like and followcount for a brand name from Graph API:
Error: global leaks detected: data_array, parsed
at Runner.checkGlobals (/Users/myth/Learn/Code/Projects/socialindex/node_modules/mocha/lib/runner.js:167:21)
at Runner.<anonymous> (/Users/myth/Learn/Code/Projects/socialindex/node_modules/mocha/lib/runner.js:58:44)
at Runner.EventEmitter.emit (events.js:126:20)
at Runner.uncaught (/Users/myth/Learn/Code/Projects/socialindex/node_modules/mocha/lib/runner.js:466:10)
at process.Runner.run (/Users/myth/Learn/Code/Projects/socialindex/node_modules/mocha/lib/runner.js:508:10)
at process.EventEmitter.emit (events.js:126:20)
2) FacebookAdapter should fetch the like and followcount for a brand name from Graph API:
Error: global leaks detected: data_array, parsed
at Runner.checkGlobals (/Users/myth/Learn/Code/Projects/socialindex/node_modules/mocha/lib/runner.js:167:21)
at Runner.<anonymous> (/Users/myth/Learn/Code/Projects/socialindex/node_modules/mocha/lib/runner.js:58:44)
at Runner.EventEmitter.emit (events.js:126:20)
at Runner.uncaught (/Users/myth/Learn/Code/Projects/socialindex/node_modules/mocha/lib/runner.js:466:10)
at process.Runner.run (/Users/myth/Learn/Code/Projects/socialindex/node_modules/mocha/lib/runner.js:508:10)
at process.EventEmitter.emit (events.js:126:20)
为什么测试执行两次?我似乎也没有滥用任何全局变量。为什么错误?