diff options
| author | Misko Hevery | 2010-11-10 16:08:54 -0800 | 
|---|---|---|
| committer | Misko Hevery | 2010-11-10 21:01:17 -0800 | 
| commit | 0499c4727036446f5c8a5722bbd9c4018dae146f (patch) | |
| tree | 334261fe7a47d325eb5d0fce653049a4d8940555 /test | |
| parent | 43a4ff4cdf4100ded15b90d49a514648a88b87b4 (diff) | |
| download | angular.js-0499c4727036446f5c8a5722bbd9c4018dae146f.tar.bz2 | |
added ng:switch-when-default; changed $watch to always fire on init. (may be backward incompatible)
Diffstat (limited to 'test')
| -rw-r--r-- | test/BinderTest.js | 8 | ||||
| -rw-r--r-- | test/CompilerSpec.js | 3 | ||||
| -rw-r--r-- | test/directivesSpec.js | 4 | ||||
| -rw-r--r-- | test/widgetsSpec.js | 28 | 
4 files changed, 34 insertions, 9 deletions
diff --git a/test/BinderTest.js b/test/BinderTest.js index 06f0a449..71b2f6b6 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -607,13 +607,13 @@ BinderTest.prototype.testItShouldListenOnRightScope = function() {        '<ul ng:init="counter=0; gCounter=0" ng:watch="w:counter=counter+1">' +        '<li ng:repeat="n in [1,2,4]" ng:watch="w:counter=counter+1;w:$root.gCounter=$root.gCounter+n"/></ul>');    c.scope.$eval(); -  assertEquals(0, c.scope.$get("counter")); -  assertEquals(0, c.scope.$get("gCounter")); +  assertEquals(1, c.scope.$get("counter")); +  assertEquals(7, c.scope.$get("gCounter"));    c.scope.$set("w", "something");    c.scope.$eval(); -  assertEquals(1, c.scope.$get("counter")); -  assertEquals(7, c.scope.$get("gCounter")); +  assertEquals(2, c.scope.$get("counter")); +  assertEquals(14, c.scope.$get("gCounter"));  };  BinderTest.prototype.testItShouldRepeatOnHashes = function() { diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js index 780fd7cb..fa63ab77 100644 --- a/test/CompilerSpec.js +++ b/test/CompilerSpec.js @@ -14,7 +14,8 @@ describe('compiler', function(){        watch: function(expression, element){          return function() {            this.$watch(expression, function(val){ -            log += ":" + val; +            if (val) +              log += ":" + val;            });          };        } diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 2e5aa2a0..a3aa2481 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -172,12 +172,12 @@ describe("directives", function(){      var scope = compile('<div ng:watch="i: count = count + 1" ng:init="count = 0">');      scope.$eval();      scope.$eval(); -    expect(scope.$get('count')).toEqual(0); +    expect(scope.$get('count')).toEqual(1);      scope.$set('i', 0);      scope.$eval();      scope.$eval(); -    expect(scope.$get('count')).toEqual(1); +    expect(scope.$get('count')).toEqual(2);    });    describe('ng:click', function(){ diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 2d1aef1a..34ea6b1d 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -430,7 +430,11 @@ describe("widget", function(){    describe('ng:switch', function(){      it('should switch on value change', function(){ -      compile('<ng:switch on="select"><div ng:switch-when="1">first:{{name}}</div><div ng:switch-when="2">second:{{name}}</div></ng:switch>'); +      compile('<ng:switch on="select">' + +          '<div ng:switch-when="1">first:{{name}}</div>' + +          '<div ng:switch-when="2">second:{{name}}</div>' + +          '<div ng:switch-when="true">true:{{name}}</div>' + +        '</ng:switch>');        expect(element.html()).toEqual('');        scope.select = 1;        scope.$eval(); @@ -444,8 +448,28 @@ describe("widget", function(){        scope.name = 'misko';        scope.$eval();        expect(element.text()).toEqual('second:misko'); +      scope.select = true; +      scope.$eval(); +      expect(element.text()).toEqual('true:misko'); +    }); +     +    it("should compare stringified versions", function(){ +      var switchWidget = angular.widget('ng:switch'); +      expect(switchWidget.equals(true, 'true')).toEqual(true);      }); +    it('should switch on switch-when-default', function(){ +      compile('<ng:switch on="select">' + +          '<div ng:switch-when="1">one</div>' + +          '<div ng:switch-default>other</div>' + +        '</ng:switch>'); +      scope.$eval(); +      expect(element.text()).toEqual('other'); +      scope.select = 1; +      scope.$eval(); +      expect(element.text()).toEqual('one'); +    }); +          it("should match urls", function(){        var scope = angular.compile('<ng:switch on="url" using="route:params"><div ng:switch-when="/Book/:name">{{params.name}}</div></ng:switch>');        scope.url = '/Book/Moby'; @@ -459,7 +483,7 @@ describe("widget", function(){        expect(match).toBeFalsy();      }); -    it('should call init on switch', function(){ +    it('should call change on switch', function(){        var scope = angular.compile('<ng:switch on="url" change="name=\'works\'"><div ng:switch-when="a">{{name}}</div></ng:switch>');        var cleared = false;        scope.url = 'a';  | 
