1

I am javascript+node beginner and also relatively new to asynchronous programming style. I am comfortable with Ruby and Rails and now trying to teach myself node.

I am working on a node app where I need to fetch data from Facebook for which I am using the 'facebook-api' node package.

I am using a BDD approach ( newcomer here as well, never used rspec much in ruby) with mocha + should.js.

Here is some of the early code I have written:

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
};

test/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();
        });
    });
});

To execute mocha test, I have a makefile in the root directory of the express application. Here is the content:

test:
    @./node_modules/.bin/mocha -u tdd
.PHONY: test

Now, when executing the tests, I always end up with the error:

․․․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)

Why is the test executing twice? I dont also seem to be misusing any globals as well. Why the error?

4

0 回答 0