This article describes the usage of the AngularJS auxiliary library browserTrigger. Share it for your reference, as follows:
Today I recommend a unit test auxiliary library browserTrigger from angularjs source code, which is a piece of code from ngScenario. The main user triggers the browser-type behavior to update the value of the scope view model in ng.
This is an example of using browserTrigger for unit tests in angularjs source code:
it('should set the model to empty string when empty option is selected', function() { = '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(('option').eq(0)); expect(element).toEqualSelect([''], 'x', 'y'); expect().toBe(''); });
In this code, pass the browserTrigger the select option you want to select, and it will help you to tiger change, select the current option, and trigger update the viewmodel of ng select.
In browserTrigger, we also have many other input boxes or html control trigger interfaces, and browser compatibility is also added. This makes our test more convenient without considering browser compatibility or different events of triggers to update scope's value.
For more information, please refer to the official test of ng and browserTrigger source code.
I hope this article will be helpful to everyone's AngularJS programming.