Handle test event in spec file

468 views
Skip to first unread message

Jithin Raveendran

unread,
Jan 9, 2020, 9:06:50 AM1/9/20
to Jasmine
I wanted to test a function which have arguments type event. Inside the function it was checking whether the event object passed (lets say eventObj) eventObj.target.checked is true or not.
How to handle this in the spec file?

If I'm planning to call the function in spec file, Ho can I create a dummy object having dummyObj.target.checked as true, so that I can get inside the if condition.

Gregg Van Hove

unread,
Jan 14, 2020, 8:19:55 PM1/14/20
to jasmi...@googlegroups.com
If I'm understanding your setup correctly, I think you should be able to make an instance of whatever event object thing your function expects to receive and set the target and checked properties on that. If you're expecting to handle an HTML event, you should be able to use the `Event` constructor (https://developer.mozilla.org/en-US/docs/Web/API/Event) to set up a valid event based on the situation you want to test.

Hope this helps. Thanks for using Jasmine!

-Gregg

Reply all
Reply to author
Forward
0 new messages