使用JQuery到.trigger('click')似乎解除了对模态的所有操作

时间:2018-03-05 20:27:08

标签: javascript jquery semantic-ui

我正在为我正在开发的模态组件编写一些单元测试。当我开始测试动作按钮,拒绝和确定时,单击时调用正确的处理程序。

我认为一种简单的方法是在按钮元素上调用jquery .click(),.trigger('click')或.tiggerHandler('click')。

然而,这样做似乎解除了点击处理程序不仅被点击的按钮,还有其他动作按钮和调光器。使模态无法退出。

let myModal = $('#confirmModalPanel');
myModal
  .modal({
    closable: false,
    onDeny: function() {
      console.log('onDeny was called');
    },
    onApprove: function() {
      console.log('onApprove was called');
    }
  });

$('#btnReset').click(() => {
  myModal.modal('show');
});

// Cannot trigger deny action from click in code. 
// The first click correctly runs but seems to unbind the click event
// from the deny button and breaks the modal functionality. Commenting
// out these lines will make the modal behave normally. 
console.log('Trying to click the accept button from code');
$('#positiveButton').trigger('click');

console.log('Trying to click the deny button from code');
$('#denyButton').trigger('click');

http://jsfiddle.net/TuckerD/fpt3rzkp/22/

0 个答案:

没有答案