search
Homephp教程PHP开发AngularJS auxiliary library browserTrigger usage example

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(&#39;<select ng-model="robot">&#39; +
       &#39;<option value="">--select--</option>&#39; +
       &#39;<option value="x">robot x</option>&#39; +
       &#39;<option value="y">robot y</option>&#39; +
      &#39;</select>&#39;);
  expect(element).toEqualSelect(&#39;&#39;, [&#39;x&#39;], &#39;y&#39;);
  browserTrigger(element.find(&#39;option&#39;).eq(0));
  expect(element).toEqualSelect([&#39;&#39;], &#39;x&#39;, &#39;y&#39;);
  expect(scope.robot).toBe(&#39;&#39;);
});

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.


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MantisBT

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.