|
2 | 2 |
|
3 | 3 | describe('ngOptions', function() {
|
4 | 4 |
|
5 |
| - var scope, formElement, element, $compile, linkLog, ngModelCtrl; |
| 5 | + var scope, formElement, element, $compile, linkLog, childListMutationObserver, ngModelCtrl; |
6 | 6 |
|
7 | 7 | function compile(html) {
|
8 | 8 | formElement = jqLite('<form name="form">' + html + '</form>');
|
@@ -151,7 +151,18 @@ describe('ngOptions', function() {
|
151 | 151 | $compile(element.contents())(scope);
|
152 | 152 | }
|
153 | 153 | };
|
154 |
| - }); |
| 154 | + }) |
| 155 | + |
| 156 | + .directive('observeChildList', function() { |
| 157 | + return { |
| 158 | + link: function(scope, element) { |
| 159 | + var config = { childList: true }; |
| 160 | + |
| 161 | + childListMutationObserver = new window.MutationObserver(noop); |
| 162 | + childListMutationObserver.observe(element[0], config); |
| 163 | + } |
| 164 | + }; |
| 165 | + }); |
155 | 166 |
|
156 | 167 | $provide.decorator('ngOptionsDirective', function($delegate) {
|
157 | 168 |
|
@@ -801,6 +812,29 @@ describe('ngOptions', function() {
|
801 | 812 | expect(options[2]).toBeMarkedAsSelected();
|
802 | 813 | });
|
803 | 814 |
|
| 815 | + |
| 816 | + if (window.MutationObserver) { |
| 817 | + //IE9 and IE10 do not support MutationObserver |
| 818 | + //Since the feature is only needed for a test, it's okay to skip these browsers |
| 819 | + it('should render the initial options only one time', function() { |
| 820 | + scope.value = 'black'; |
| 821 | + scope.values = ['black', 'white', 'red']; |
| 822 | + // observe-child-list adds a MutationObserver that we will read out after ngOptions |
| 823 | + // has been compiled |
| 824 | + createSelect({ |
| 825 | + 'ng-model':'value', |
| 826 | + 'ng-options':'value.name for value in values', |
| 827 | + 'observe-child-list': '' |
| 828 | + }); |
| 829 | + |
| 830 | + var optionEls = element[0].querySelectorAll('option'); |
| 831 | + var records = childListMutationObserver.takeRecords(); |
| 832 | + |
| 833 | + expect(records.length).toBe(1); |
| 834 | + expect(records[0].addedNodes).toEqual(optionEls); |
| 835 | + }); |
| 836 | + } |
| 837 | + |
804 | 838 | describe('disableWhen expression', function() {
|
805 | 839 |
|
806 | 840 | describe('on single select', function() {
|
@@ -2966,6 +3000,30 @@ describe('ngOptions', function() {
|
2966 | 3000 | optionsSetSelected[0].calls.reset();
|
2967 | 3001 | optionsSetSelected[1].calls.reset();
|
2968 | 3002 | });
|
| 3003 | + |
| 3004 | + if (window.MutationObserver) { |
| 3005 | + //IE9 and IE10 do not support MutationObserver |
| 3006 | + //Since the feature is only needed for a test, it's okay to skip these browsers |
| 3007 | + it('should render the initial options only one time', function() { |
| 3008 | + scope.value = ['black']; |
| 3009 | + scope.values = ['black', 'white', 'red']; |
| 3010 | + // observe-child-list adds a MutationObserver that we will read out after ngOptions |
| 3011 | + // has been compiled |
| 3012 | + createSelect({ |
| 3013 | + 'ng-model':'selected', |
| 3014 | + 'ng-options':'value.name for value in values', |
| 3015 | + 'multiple': 'true', |
| 3016 | + 'observe-child-list': '' |
| 3017 | + }); |
| 3018 | + |
| 3019 | + var optionEls = element[0].querySelectorAll('option'); |
| 3020 | + var records = childListMutationObserver.takeRecords(); |
| 3021 | + |
| 3022 | + expect(records.length).toBe(1); |
| 3023 | + expect(records[0].addedNodes).toEqual(optionEls); |
| 3024 | + }); |
| 3025 | + } |
| 3026 | + |
2969 | 3027 | });
|
2970 | 3028 |
|
2971 | 3029 |
|
|
0 commit comments