We need to test a function which evaluates the top position of an element. In the following example an element with an id 'test'.
function xxx(){
var element = $('#test');
return element[0].getBoundingClientRect().top;
}
In order to test this function with jasmine we tried the following test approach:
var myObj = {
name: 'test',
getBoundingClientRect: function () {
return {top: 100}
}
}
spyOn($('#test'), 'getBoundingClientRect').and.returnValue([myObj]);
and get the error:
Error: <spyOn> : getBoundingClientRect() method does not exist
Usage: spyOn(<object>, <methodName>) (line 4740)