Home> php教程> PHP开发> body text

AngularJS auxiliary library browserTrigger usage example

高洛峰
Release: 2016-12-08 09:23:45
Original
1143 people have browsed it

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(''); expect(element).toEqualSelect('', ['x'], 'y'); browserTrigger(element.find('option').eq(0)); expect(element).toEqualSelect([''], 'x', 'y'); expect(scope.robot).toBe(''); });
Copy after login

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.


Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!