This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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 Murach's Java Servlets and JSP this week in the Servlets 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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Testing javascript function that is not within an object
 
Similar Threads
passing the parameters from the ajax calling function to the 'onreadystatechange' method.
protected method access and inheritence
Var-args and method overloading doubt
How to stop setTimeOut method
Making a Post request using Ajax