Rajni
Rajni

Reputation: 95

How to test nested function in jasmine?

can we test nested function in jasmine? its giving an error as "Cannot read property 'inner' of undefined". Please look into the following,

My test file is,

describe('sample.js', function(){
        it('test', function(){
            expect(outer()).toBe(true);
            expect(inner()).toBe(true);
        });
    });

And java script file is,

 function outer(){
        function inner(){
            return true;
        };
        return true;
    };

Upvotes: 2

Views: 1140

Answers (1)

Roman
Roman

Reputation: 4513

You can't test nested functions - as they're private inside the father function.

The solution would be to move it outside of the nested function. Such as:

function outer() { return true; } function inner() { return true; }

Upvotes: 2

Related Questions