3

app.js

function _private() {
    console.log( '_private' );
}

function public() {
    console.log( 'public' );
    _private();
}

module.exports = {
    public: public,
    _private: _private
};

spec/appSpec.js

describe( 'test', function() {
    it( 'will spy on _private', function() {
        var app = require( '../app' );
        spyOn( app, '_private' );
        app.public();
        expect( app._private ).toHaveBeenCalled();
    });
});

_private() is called, but the spy doesn't work and the test fails.

So as the question asks, how do I hook the spy up so that it knows that _private() was called? Or is this not possible?

ggutenberg
  • 6,880
  • 8
  • 39
  • 48

1 Answers1

0

You can call _private with this otherwise the function is not defined. try this:

function public() {
    console.log( 'public' );
    this._private();
}
leobelizquierdo
  • 1,648
  • 12
  • 20