This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Testing javascript function that is not within an object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Testing javascript function that is not within an object" Watch "Testing javascript function that is not within an object" New topic
Author

Testing javascript function that is not within an object

Amit Bhargava
Greenhorn

Joined: May 20, 2011
Posts: 20
I've got a function as follows:



callMethod is another function in the same js file being tested. Both functions are not within any object.

I want to set a spy on callMethod, but am unable to do so. I keep getting errors in Jasmine stating 'callMethod() method does not exist'

What should be the object that is set as the first parameter of spyOn()?
Amit Bhargava
Greenhorn

Joined: May 20, 2011
Posts: 20
Just noticed I've accidentally posted this in the wrong forum. How do I move it to 'JSP'?
Paul Clapham
Sheriff

Joined: Oct 14, 2005
Posts: 19728
    
  10

JSP? But it's a question about Javascript. Can't possibly have anything to do with JSP. But we can move it to the HTML/Javascript forum... it is about Javascript, after all.
Amit Bhargava
Greenhorn

Joined: May 20, 2011
Posts: 20
Thanks Paul!
Amit Bhargava
Greenhorn

Joined: May 20, 2011
Posts: 20
Finally got around it by creating a fake object. The fake object calls the desired function and is spied on.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Testing javascript function that is not within an object
 
It's not a secret anymore!