Jasmine 上的错误 - 在 #DIV_ID 上触发了预期的事件点击

2022-01-11 00:00:00 jasmine jquery javascript jasmine-jquery

我在 Jasmine 框架中开发测试工具时参考此链接触发事件:

I am referred this link to trigger a event when developing a testing tool in Jasmine framework:

http://www.htmlgoodies.com/beyond/javascript/js-ref/testing-dom-events-using-jquery-and-jasmine-2.0.html

在 Jasmine 框架中触发 #DIV_ID 上的点击事件后,我试图获取新应用的 CSS 属性.

I am trying to get the newly applied CSS attribute after triggering a click event on #DIV_ID in Jasmine framework.

我试过这个代码:

 spyEvent = spyOnEvent('#DIV_ID', 'click');
 $('#DIV_ID').trigger( "click" );
 expect('click').toHaveBeenTriggeredOn('#DIV_ID');
 expect(spyEvent).toHaveBeenTriggered();

但我收到错误消息:预计事件点击已在#DIV_ID 上触发

谁能帮我解决我的问题.

Anyone help me to resolve my problem.

提前致谢.

推荐答案

你的代码有语法错误:

 var spyEvent = spyOnEvent($('#DIV_ID'), 'click');
 $('#DIV_ID').trigger( "click" );
 expect('click').toHaveBeenTriggeredOn($('#DIV_ID'));
 expect(spyEvent).toHaveBeenTriggered();

我希望这行得通.

相关文章