diff options
| author | Misko Hevery | 2011-07-14 13:27:39 -0700 | 
|---|---|---|
| committer | Misko Hevery | 2011-07-26 09:41:43 -0700 | 
| commit | 7802c90e139a36d37b9d3c8cd6b6fcfee042dd71 (patch) | |
| tree | 3dcdea5cfe93a80bc0d5dee68d45c87b4f7f8908 /test/widgetsSpec.js | |
| parent | c348f2cad6e2db0c3a37108eb34c8d62f2b7c718 (diff) | |
| download | angular.js-7802c90e139a36d37b9d3c8cd6b6fcfee042dd71.tar.bz2 | |
fix(directive): ng:options to support iterating over objects
Closes #448
Diffstat (limited to 'test/widgetsSpec.js')
| -rw-r--r-- | test/widgetsSpec.js | 51 | 
1 files changed, 50 insertions, 1 deletions
diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 342dc8c5..422ca86b 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -611,7 +611,7 @@ describe("widget", function(){      it('should throw when not formated "? for ? in ?"', function(){        expect(function(){          compile('<select name="selected" ng:options="i dont parse"></select>'); -      }).toThrow("Expected ng:options in form of '(_expression_ as)? _expresion_ for _item_ in _collection_' but got 'i dont parse'."); +      }).toThrow("Expected ng:options in form of '_select_ (as _label_)? for (_key_,)?_value_ in _collection_' but got 'i dont parse'.");        $logMock.error.logs.shift();      }); @@ -628,6 +628,27 @@ describe("widget", function(){        expect(sortedHtml(options[2])).toEqual('<option value="2">C</option>');      }); +    it('should render an object', function(){ +      createSelect({ +        name:'selected', +        'ng:options': 'value as key for (key, value) in object' +      }); +      scope.object = {'red':'FF0000', 'green':'00FF00', 'blue':'0000FF'}; +      scope.selected = scope.object.red; +      scope.$eval(); +      var options = select.find('option'); +      expect(options.length).toEqual(3); +      expect(sortedHtml(options[0])).toEqual('<option value="0">blue</option>'); +      expect(sortedHtml(options[1])).toEqual('<option value="1">green</option>'); +      expect(sortedHtml(options[2])).toEqual('<option value="2">red</option>'); +      expect(options[2].selected).toEqual(true); + +      scope.object.azur = '8888FF'; +      scope.$eval(); +      options = select.find('option'); +      expect(options[3].selected).toEqual(true); +    }); +      it('should grow list', function(){        createSingleSelect();        scope.values = []; @@ -751,6 +772,34 @@ describe("widget", function(){          expect(select.val()).toEqual('1');        }); +      it('should bind to object key', function(){ +        createSelect({ +          name:'selected', +          'ng:options':'key as value for (key, value) in object'}); +        scope.object = {'red':'FF0000', 'green':'00FF00', 'blue':'0000FF'}; +        scope.selected = 'green'; +        scope.$eval(); +        expect(select.val()).toEqual('1'); + +        scope.selected = 'blue'; +        scope.$eval(); +        expect(select.val()).toEqual('0'); +      }); + +      it('should bind to object value', function(){ +        createSelect({ +          name:'selected', +          'ng:options':'value as key for (key, value) in object'}); +        scope.object = {'red':'FF0000', 'green':'00FF00', 'blue':'0000FF'}; +        scope.selected = '00FF00'; +        scope.$eval(); +        expect(select.val()).toEqual('1'); + +        scope.selected = '0000FF'; +        scope.$eval(); +        expect(select.val()).toEqual('0'); +      }); +        it('should insert a blank option if bound to null', function(){          createSingleSelect();          scope.values = [{name:'A'}];  | 
