The example in this article describes the usage of AngularJS auxiliary library browserTrigger. Share it with everyone for your reference, the details are as follows:
Today I recommend a unit test auxiliary library browserTrigger from the angularjs source code. This is a piece of code from ngScenario. The main user triggers browser-type behavior to update the value of the scope view model in ng.
This is an example of using browserTrigger for unit testing in angularjs source code:
it('should set the model to empty string when empty option is selected', function() { scope.robot = 'x'; compile('<select ng-model="robot">' + '<option value="">--select--</option>' + '<option value="x">robot x</option>' + '<option value="y">robot y</option>' + '</select>'); expect(element).toEqualSelect('', ['x'], 'y'); browserTrigger(element.find('option').eq(0)); expect(element).toEqualSelect([''], 'x', 'y'); expect(scope.robot).toBe(''); });
In this code, pass in the select option you want to select to browserTrigger, and it will help you tigger change and select the current option. It also triggers the update of the viewmodel of ng select.
In browserTrigger, we also made many other trigger interfaces for input boxes or HTML controls, and also added browser compatibility. This makes our testing more convenient without having to consider browser compatibility or different HTML controls triggering different events to update the scope value.
For more information, please refer to ng’s official test and browserTrigger source code.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Notepad++7.3.1
Easy-to-use and free code editor

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
