Qunit usage notes-3 test user operations

Source: Internet
Author: User

Simulated operation:

  • ELEM. Trigger (event );
  • ELEM. triggerhandler (event );
    • Different triggerhandler:
      • Does not cause default event Behavior
      • . Trigger () will operate on all elements matched by the jquery object, while. triggerhandler () only affects the First Matching Element.
      • Events created by. triggerhandler () are not bubbling in the DOM tree.
      • This method returns the return value of the event processing function, rather than the jquery object.
  • $. Event (event); if the event needs to depend on a specific operation for other operations, use event and set properties:
    event = $.Event("keydown");  //keydown event;    event.keyCode = 9;    $doc.trigger(event);//can use triggerHandler() insteadof trigger;

Example:

function keyLogger(target) {    if(!(this instanceof keyLogger)) {        return new keyLogger(target);    };    this.target = target;    this.log = [];    var self = this;    this.target.off("keydown").on("keydown", function(event) {        self.log.push(event.keyCode);    });}QUnit.test("keylogger api behavior", function(assert) {    var event,        $doc = $(document),        keys = keyLogger($doc);    //trigger event    event = $.Event("keydown");  //keydown event;    event.keyCode = 9;    $doc.trigger(event);//can use triggerHandler() insteadof trigger;    //verify expected behavior    assert.equal(keys.log.length,1,"a key was logged");    assert.equal(keys.log[0],9,"correct key was logged");    });

  

 

Qunit usage notes-3 test user operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.