javascript - Stubbing event property in Jasmine Test -


I am very new to writing Jasmine tests and need some help.

Actually, I call a function below one function and passes the event handler (so basically when the link is clicked on the page, then the context of the event will be replaced by any other function Is sent on so that I can recover the contents of the internal text content of the event):

  $ ('$ clickME'). Click (function (e) {return self.CallAnotherFunction (e);}); Function call endotherfunction (MyEvent) {myevent.preventDefault (); var source = myevent.target || myevent.srcElement; }   

Now in my jasmine test:

  this should be read ('clicked item text', function () {var event = {preventDefault : Jasmine .createSpy ()}; //event.source.innerText = "ff"; // act myObject.prototype.CallAnotherFunction (Event);});   

The problem is that when I run the exam, it fails with the error below:

Type error: 'undefined' is not an object (evaluation ' Source.innertext ')

So it seems that I have created a spy incident, it is a weak source.

My question is, how do I get event.target & amp; Event.srcElement is so much on the spy event that my exam can pass.

Thanks

The solution given above was found:

A stub installed on the spy requires a new counterfeit object using the createSpy software, so to set a magic detective work, add the following:

  var event = {PreventDefault: jasmine.createSpy (), srcElement: jasmine.createSpy ()}; Event.srcElement.innerText = 'Some values ​​of anchor tag';    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -