This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara 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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA 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.
 
Don't get me started about those stupid light bulbs.
 
subject: Testing javascript function that is not within an object