CuriousFellow CuriousFellow - 6 months ago 8
Node.js Question

Function parameter failing to execute in Node.JS Jasmine test

I'm trying to execute a function that is passed in as a parameter in my Jasmine test.

I'm calling my function within this for-loop, but getting

"TypeError: barbican_function is not a function"


/************************************************************************
Stress Test Code to Test High Request Hits To API Endpoint
**************************************************************************/
//Stress Test for Key Retrieval
var stressTestRunner = function(barbican_function) {
describe("Stress test", function() {
it("Send X requests to single key", function(done) {
for (var x = 0; x < requestsToHit; x++) {
barbican_function();
}
done();
})
})
};

stressTestRunner(stressTest_retrieve_secret());




function stressTest_retrieve_secret() {

//My code here
};

Answer

Because of this line:

stressTestRunner(stressTest_retrieve_secret());

You are calling the function and passing in the function's return value.

What you most likely mean is:

stressTestRunner(stressTest_retrieve_secret);

which passes in a function reference.

Debugging hint: Next time you get an error like this, open up your browser's debugging tools and put a breakpoint on your code. That would let you examine the various variable and parameters to see what is going on.

Comments