admin管理员组文章数量:1429637
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.
本文标签: javascriptTesting toUpperCase with JasmineStack Overflow
版权声明:本文标题:javascript - Testing toUpperCase with Jasmine - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745480316a2660144.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论