diff options
| author | TEHEK Firefox | 2011-10-11 22:37:00 +0000 | 
|---|---|---|
| committer | Igor Minar | 2011-10-19 22:52:14 -0700 | 
| commit | 36928858104ba793dfc7372dbaa28048123d6e63 (patch) | |
| tree | a797722f18f0da73316e5660f046f336c9e0c474 /test | |
| parent | 5d43439dbe764a4c7227f51b34a81b044f13901b (diff) | |
| download | angular.js-36928858104ba793dfc7372dbaa28048123d6e63.tar.bz2 | |
fix(ng:options): compile null/blank option tag
Fixes #562
Diffstat (limited to 'test')
| -rw-r--r-- | test/widget/selectSpec.js | 78 | 
1 files changed, 76 insertions, 2 deletions
diff --git a/test/widget/selectSpec.js b/test/widget/selectSpec.js index 63699d01..c3fdc2e6 100644 --- a/test/widget/selectSpec.js +++ b/test/widget/selectSpec.js @@ -130,8 +130,8 @@ describe('select', function() {          }        });        html += '>' + -        (blank ? '<option value="">blank</option>' : '') + -        (unknown ? '<option value="?">unknown</option>' : '') + +        (blank ? (isString(blank) ? blank : '<option value="">blank</option>') : '') + +        (unknown ? (isString(unknown) ? unknown : '<option value="?">unknown</option>') : '') +        '</select>';        select = jqLite(html);        scope = compile(select); @@ -445,6 +445,80 @@ describe('select', function() {        });      }); + +    describe('blank option', function () { +      it('should be compiled as template, be watched and updated', function () { +        var option; + +        createSingleSelect('<option value="">blank is {{blankVal}}</option>'); +        scope.blankVal = 'so blank'; +        scope.values = [{name:'A'}]; +        scope.$digest(); + +        // check blank option is first and is compiled +        expect(select.find('option').length == 2); +        option = jqLite(select.find('option')[0]); +        expect(option.val()).toBe(''); +        expect(option.text()).toBe('blank is so blank'); + +        // change blankVal and $digest +        scope.blankVal = 'not so blank'; +        scope.$digest(); + +        // check blank option is first and is compiled +        expect(select.find('option').length == 2); +        option = jqLite(select.find('option')[0]); +        expect(option.val()).toBe(''); +        expect(option.text()).toBe('blank is not so blank'); +      }); + +      it('should support binding via ng:bind-template attribute', function () { +        var option; + +        createSingleSelect('<option value="" ng:bind-template="blank is {{blankVal}}"></option>'); +        scope.blankVal = 'so blank'; +        scope.values = [{name:'A'}]; +        scope.$digest(); + +        // check blank option is first and is compiled +        expect(select.find('option').length == 2); +        option = jqLite(select.find('option')[0]); +        expect(option.val()).toBe(''); +        expect(option.text()).toBe('blank is so blank'); +      }); + +      it('should support biding via ng:bind attribute', function () { +        var option; + +        createSingleSelect('<option value="" ng:bind="blankVal"></option>'); +        scope.blankVal = 'is blank'; +        scope.values = [{name:'A'}]; +        scope.$digest(); + +        // check blank option is first and is compiled +        expect(select.find('option').length == 2); +        option = jqLite(select.find('option')[0]); +        expect(option.val()).toBe(''); +        expect(option.text()).toBe('is blank'); +      }); + +      it('should be rendered with the attributes preserved', function () { +        var option; + +        createSingleSelect('<option value="" class="coyote" id="road-runner" ' + +          'custom-attr="custom-attr">{{blankVal}}</option>'); +        scope.blankVal = 'is blank'; +        scope.$digest(); + +        // check blank option is first and is compiled +        option = jqLite(select.find('option')[0]); +        expect(option.hasClass('coyote')).toBeTruthy(); +        expect(option.attr('id')).toBe('road-runner'); +        expect(option.attr('custom-attr')).toBe('custom-attr'); +      }); +    }); + +      describe('on change', function() {        it('should update model on change', function() {          createSingleSelect();  | 
