IE 中的单元测试事件处理程序
我的应用程序的一部分仅在某些情况下阻止对事件的默认操作。我严格按照 TDD 工作,因此我需要测试默认事件是否在正确的时间被阻止。这在大多数现代浏览器中都很容易,因为 dispatchEvent
等将触发我的事件处理程序和默认事件处理程序,并且我可以测试默认事件(哈希更改)是否发生。但 IE 的 fireEvent 不会这样做...它只会触发我的处理程序,因此无法测试它是否按预期完成,而无需在某处发生手动单击。
我的事件处理程序没有公开,即使公开了,测试它是否返回 false 与测试实现有点太接近了。有没有教科书上的方法来处理我所缺少的这个问题?
Part of my application prevents the default action on an event only under certain circumstances. I'm working strictly TDD, and so I need to test that the default event is being prevented at the right time. This is easy in most modern browsers, as dispatchEvent
et al will trigger both my event handler and the default, and I can test if the default event (hash change) has happened. IEs fireEvent doesn't do that though... It only triggers my handler, so there's no way to test if it's done as it should without a manual click happening somewhere.
My event handler isn't exposed, and even if it was, testing if it returned false would be a bit too close to testing the implementation. Is there a textbook way for handling this that I'm missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
浏览器在网页中执行的 JavaScript 是沙盒的,无法访问诸如 本机事件队列。使用本机 IE 自动化控件来满足您的需求或作为软件包的一部分例如作为完整解决方案的 Internet Explorer 驱动程序。
JavaScript executed in a web page by a browser is sandboxed and has no access to things such as the native event queue. Use native IE Automation Controls to fit your needs or as part of a package such as Internet Explorer Driver as a complete solution.