Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

311
Views
Error in Karma Unit Test: TypeError: event.preventDefault is not a function error

I'm trying to test this function:

@HostListener("keydown", [$event])
onKeyDown(event){
 if(event.keyCode===32 || event.keyCode===13){
    event.preventDefault();
    this.nameClicked.emit(this.name);
 }
}

However, I received this error in Karma: TypeError: event.preventDefault is not a function error.

This is the code for my unit test:

it("should emit name and call onKeyDown when pressed:, () => {

  const spy = spyOn(component.nameClicked, "emit");

  const event = {keyCode: 13};

  component.onKeyDown(event);

  expect(spy).toHaveBeenCalled();

 });
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!