How to assert a spy is invoked with event on click using jasmine?

后端 未结 2 1921
太阳男子
太阳男子 2021-01-02 02:19

I\'m writing a simple click handler and need the event passed in (like so)

Thing = function($){

    var MyObject = function(opts){
        this.opts = opts;         


        
2条回答
  •  情深已故
    2021-01-02 03:10

    If you can't use jQuery you may use dispatchEvent and check its return value (based on this answer).

    const domElem = document.getElementById('some_dom_element');
    const clickEvent = new MouseEvent('click', {
      view: window,
      bubbles: true,
      cancelable: true
    });
    
    const cancelled = !domElem.dispatchEvent(clickEvent);
    expect(cancelled).toBeTruthy();
    

提交回复
热议问题