久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

模擬 TDD JavaScript 的用戶輸入

Simulating user input for TDD JavaScript(模擬 TDD JavaScript 的用戶輸入)
本文介紹了模擬 TDD JavaScript 的用戶輸入的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

I'm finding it increasingly difficult to simulate actual user events using jQuery or native element trigger functions. For example, if you have a text input and you don't want the user to be able to add a character, you can call e.preventDefault() with the jQuery-normalised event object on the keydown event. However, there is no way to programatically verify this test scenario.

The following test passes even without the call to preventDefault because the jQuery keydown trigger isn't a "real" event.

input.val('test').trigger(jQuery.Event({
    which: 68
});
expect(input).toHaveValue('test');

Without the correct code, this test should fail because the input should have a value of 'testd' (68 is the character code for 'd').

Does anyone know any methods or libraries to simulate real browser UI events?

解決方案

Simulate real event is quite complicated. You must first determine which type of event you need and create it with document.createEvent. Then call different init*Event to initialize the event object. Finally, use element.dispatchEvent to dispatch the event to the target object.

這篇關于模擬 TDD JavaScript 的用戶輸入的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I get my jasmine tests fixtures to load before the javascript considers the document to be quot;readyquot;?(在 javascript 認為文檔“準備好之前,如何讓我的 jasmine 測試裝置加載?) - IT屋-程序員軟件開發技術
What do jasmine runs and waitsFor actually do?(jasmine 運行和等待實際上是做什么的?)
How to provide mock files to change event of lt;input type=#39;file#39;gt; for unit testing(如何提供模擬文件來更改 lt;input type=filegt; 的事件用于單元測試)
How to unit test a chained method using Jasmine(如何使用 Jasmine 對鏈式方法進行單元測試)
How do I inject $rootScope into an AngularJS unit test?(如何將 $rootScope 注入 AngularJS 單元測試?)
Jasmine - How to spy on a function call within a function?(Jasmine - 如何監視函數中的函數調用?)
主站蜘蛛池模板: 91福利网址 | 污免费网站 | 一区二区视频在线 | 国产福利在线小视频 | 成人午夜免费视频 | 999热视频| 午夜精品久久久久久久 | 黄色毛片在线播放 | 97色在线观看免费视频 | 成人免费看 | 成人做爰69片免费观看 | 国产成人免费视频网站视频社区 | 精品一区二区久久久久久久网站 | 综合久| 欧美在线a | 国产在线观看av | av黄色片在线观看 | 亚洲精品一区中文字幕 | 精品欧美一区二区三区精品久久 | 97免费视频在线观看 | 成人毛片视频免费 | 日日夜夜av| 国产精品99久久久久久www | 精品一区在线 | 美女国产一区 | 99久久久国产精品免费消防器 | 青青草原精品99久久精品66 | 亚洲一区二区三区视频 | 天天躁日日躁aaaa视频 | 国产午夜精品理论片a大结局 | 免费在线性爱视频 | 亚洲精品成人网 | 国产精彩视频一区 | 国产乱码精品1区2区3区 | 国产精品久久久久久久久免费丝袜 | 国产免费拔擦拔擦8x高清 | 欧美精品91 | 亚洲一区二区久久 | 欧美日韩亚洲在线 | 无码一区二区三区视频 | 米奇成人网 |