I'm trying to test if the String.toUpperCase
method is called with Jasmine. However whenever I try it just returns
toUpperCase() method does not exist
Here is my Jasmine test:
spyOn(String,"toUpperCase")
$(@makeup.el).trigger(@e)
expect(String.toUpperCase).toHaveBeenCalled()
Any ideas on how to test if that is called? It appears that String
is a private class to the window
object, and so I may not actually be able to test this. Please help.
I'm trying to test if the String.toUpperCase
method is called with Jasmine. However whenever I try it just returns
toUpperCase() method does not exist
Here is my Jasmine test:
spyOn(String,"toUpperCase")
$(@makeup.el).trigger(@e)
expect(String.toUpperCase).toHaveBeenCalled()
Any ideas on how to test if that is called? It appears that String
is a private class to the window
object, and so I may not actually be able to test this. Please help.
1 Answer
Reset to default 7There is no String.toUpperCase
function. There is, however, a String.prototype.toUpperCase
function which is what "pancakes".toUpperCase()
will use. You should have better luck with:
spyOn(String.prototype, 'toUpperCase')
#...
expect(String.prototype.toUpperCase).toHaveBeenCalled()
However, native functions aren't guaranteed to behave like functions that are implemented in JavaScript so don't be surprised if this doesn't work either.
Checking that the toUpperCase
method has been called anywhere (which is what wrapping String.prototype.toUpperCase
with a spy will do) seems a bit pointless since strings are used all over the place; spying on a particular string would make more sense but even then, this particular test still seems a bit pointless.