How can I write unit test cases for click method in given jquery nested function?

Viewed 19

My Component code is given below

import { Component, OnInit} from ‘@angular/core’;
import * as $ from 'jquery' 
export class AppComponent implements OnInit {
ngOnInit(){
$(document).ready(function(){
            $("button").click(function(){
                var div=$("div");
                div.animate({left:'100px'}, "slow");
                div.animate({fontSize:'5em'}, "slow");
            });
        });
}

I have tried spyOn method but it gives me error on click method.

  it('should call $(document).ready(function ())', () => {
    spyOn($.fn,'click').and.callThrough();
    component.ngOnInit();
    expect($.fn.click).toHaveBeenCalled();
  });

error : Expected spy click to have been called.

0 Answers
Related