diff options
| author | Misko Hevery | 2010-04-05 11:46:53 -0700 |
|---|---|---|
| committer | Misko Hevery | 2010-04-05 11:46:53 -0700 |
| commit | 7a4b48020688060debe9cb0f9c17615d7585cbe7 (patch) | |
| tree | 48a5b1d8cf92bb272028a106ab9ea3ec16f477a2 /test | |
| parent | 4bfa4e230d5ebdd582068effe7f4f1b60c43093a (diff) | |
| download | angular.js-7a4b48020688060debe9cb0f9c17615d7585cbe7.tar.bz2 | |
added ng:switch widget
Diffstat (limited to 'test')
| -rw-r--r-- | test/BinderTest.js | 15 | ||||
| -rw-r--r-- | test/ScenarioSpec.js | 12 | ||||
| -rw-r--r-- | test/ScopeSpec.js | 2 | ||||
| -rw-r--r-- | test/ValidatorsTest.js | 2 | ||||
| -rw-r--r-- | test/angular-mocks.js | 26 | ||||
| -rw-r--r-- | test/servicesSpec.js | 8 | ||||
| -rw-r--r-- | test/testabilityPatch.js | 40 | ||||
| -rw-r--r-- | test/widgetsSpec.js | 16 |
8 files changed, 54 insertions, 67 deletions
diff --git a/test/BinderTest.js b/test/BinderTest.js index fa3127d7..660ad78c 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -629,21 +629,6 @@ BinderTest.prototype.testDeleteAttributeIfEvaluatesFalse = function() { assertChild(5, false); }; -BinderTest.prototype.testRepeaterErrorShouldBePlacedOnInstanceNotOnTemplateComment = function () { - var c = this.compile( - '<input name="person.{{name}}" ng-repeat="name in [\'a\', \'b\']" />'); - c.scope.$eval(); - assertTrue(c.node.hasClass("ng-exception")); -}; - -BinderTest.prototype.testItShouldApplyAttributesBeforeTheWidgetsAreMaterialized = function() { - var c = this.compile( - '<input name="person.{{name}}" ng-repeat="name in [\'a\', \'b\']" />'); - c.scope.$set('person', {a:'misko', b:'adam'}); - c.scope.$eval(); - assertEquals("", c.node.html()); -}; - BinderTest.prototype.XtestItShouldCallListenersWhenAnchorChanges = function() { var log = ""; var c = this.compile('<div ng-watch="$anchor.counter:count = count+1">'); diff --git a/test/ScenarioSpec.js b/test/ScenarioSpec.js index 5b88a175..ff3a55b5 100644 --- a/test/ScenarioSpec.js +++ b/test/ScenarioSpec.js @@ -1,26 +1,26 @@ describe("ScenarioSpec: Compilation", function(){ it("should compile dom node and return scope", function(){ var node = jqLite('<div ng-init="a=1">{{b=a+1}}</div>')[0]; - var scope = angular.compile(node); + var scope = compile(node); scope.$init(); expect(scope.a).toEqual(1); expect(scope.b).toEqual(2); }); it("should compile jQuery node and return scope", function(){ - var scope = angular.compile(jqLite('<div>{{a=123}}</div>')).$init(); + var scope = compile(jqLite('<div>{{a=123}}</div>')).$init(); expect(jqLite(scope.$element).text()).toEqual('123'); }); it("should compile text node and return scope", function(){ - var scope = angular.compile('<div>{{a=123}}</div>').$init(); + var scope = compile('<div>{{a=123}}</div>').$init(); expect(jqLite(scope.$element).text()).toEqual('123'); }); }); describe("ScenarioSpec: Scope", function(){ xit("should have set, get, eval, $init, updateView methods", function(){ - var scope = angular.compile('<div>{{a}}</div>').$init(); + var scope = compile('<div>{{a}}</div>').$init(); scope.$eval("$invalidWidgets.push({})"); expect(scope.$set("a", 2)).toEqual(2); expect(scope.$get("a")).toEqual(2); @@ -31,7 +31,7 @@ describe("ScenarioSpec: Scope", function(){ }); xit("should have $ objects", function(){ - var scope = angular.compile('<div></div>', {a:"b"}); + var scope = compile('<div></div>', {a:"b"}); expect(scope.$get('$anchor')).toBeDefined(); expect(scope.$get('$eval')).toBeDefined(); expect(scope.$get('$config')).toBeDefined(); @@ -49,7 +49,7 @@ xdescribe("ScenarioSpec: configuration", function(){ set:function(u){url = u;}, get:function(){return url;} }; - var scope = angular.compile("<div>{{$anchor}}</div>", {location:location}); + var scope = compile("<div>{{$anchor}}</div>", {location:location}); var $anchor = scope.$get('$anchor'); expect($anchor.book).toBeUndefined(); expect(onUrlChange).toBeUndefined(); diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js index a7322cae..09f4d875 100644 --- a/test/ScopeSpec.js +++ b/test/ScopeSpec.js @@ -44,7 +44,7 @@ describe('scope/model', function(){ model.$onEval(function(){evalCount ++;}); model.name = 'misko'; model.$eval(); - expect(nameCount).toEqual(1); + expect(nameCount).toEqual(2); expect(evalCount).toEqual(1); expect(model.newValue).toEqual('misko'); expect(model.oldValue).toEqual('adam'); diff --git a/test/ValidatorsTest.js b/test/ValidatorsTest.js index 37be526d..d7da28cd 100644 --- a/test/ValidatorsTest.js +++ b/test/ValidatorsTest.js @@ -106,7 +106,7 @@ describe('Validator:asynchronous', function(){ it('should make a request and show spinner', function(){ var value, fn; - var scope = angular.compile('<input type="text" name="name" ng-validate="asynchronous:asyncFn"/>'); + var scope = compile('<input type="text" name="name" ng-validate="asynchronous:asyncFn"/>'); scope.$init(); var input = scope.$element; scope.asyncFn = function(v,f){ diff --git a/test/angular-mocks.js b/test/angular-mocks.js new file mode 100644 index 00000000..ab3638b1 --- /dev/null +++ b/test/angular-mocks.js @@ -0,0 +1,26 @@ + +function MockBrowser() { + this.url = "http://server"; + this.watches = []; +} +MockBrowser.prototype = { + xhr: function(method, url, callback) { + + }, + + getUrl: function(){ + return this.url; + }, + + setUrl: function(url){ + this.url = url; + }, + + watchUrl: function(fn) { + this.watches.push(fn); + } +}; + +angular.service('$browser', function(){ + return new MockBrowser(); +}); diff --git a/test/servicesSpec.js b/test/servicesSpec.js index 193351d1..43511853 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -10,7 +10,7 @@ describe("services", function(){ }); it("should inject $location", function(){ - scope.$location('http://host:123/p/a/t/h.html?query=value#path?key=value'); + scope.$location.parse('http://host:123/p/a/t/h.html?query=value#path?key=value'); expect(scope.$location.href).toEqual("http://host:123/p/a/t/h.html?query=value#path?key=value"); expect(scope.$location.protocol).toEqual("http"); expect(scope.$location.host).toEqual("host"); @@ -24,11 +24,11 @@ describe("services", function(){ scope.$location.hashPath = 'page=http://path'; scope.$location.hashSearch = {k:'a=b'}; - expect(scope.$location()).toEqual('http://host:123/p/a/t/h.html?query=value#page=http://path?k=a%3Db'); + expect(scope.$location.toString()).toEqual('http://host:123/p/a/t/h.html?query=value#page=http://path?k=a%3Db'); }); it('should parse file://', function(){ - scope.$location('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html'); + scope.$location.parse('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html'); expect(scope.$location.href).toEqual("file:///Users/Shared/misko/work/angular.js/scenario/widgets.html"); expect(scope.$location.protocol).toEqual("file"); expect(scope.$location.host).toEqual(""); @@ -39,7 +39,7 @@ describe("services", function(){ expect(scope.$location.hashPath).toEqual(''); expect(scope.$location.hashSearch).toEqual({}); - expect(scope.$location()).toEqual('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html#'); + expect(scope.$location.toString()).toEqual('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html#'); }); xit('should add stylesheets', function(){ diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 752f8ef2..b2ee5526 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -5,46 +5,6 @@ function nakedExpect(obj) { return expect(angular.fromJson(angular.toJson(obj))); } -swfobject = { - createSwf:function() { - fail("must mock out swfobject.createSwf in test."); - } -}; - -function html(content) { - return jQuery("<div></div>").html(content); -} - -function report(reportTest){ - $("#tests").children().each(function(i){ - var success = this.className == "pass"; - var strong = this.firstChild; - var msg = strong.firstChild.nodeValue; - var parts = msg.split(" module: "); - var module = parts[0]; - var name = parts[1].replace(/ *$/, ""); - reportTest(success, module, name, this.nodeValue); - }); -} - -function MockBrowser() { - this.url = "http://server"; - this.watches = []; -} -MockBrowser.prototype = { - getUrl: function(){ - return this.url; - }, - - setUrl: function(url){ - this.url = url; - }, - - watchUrl: function(fn) { - this.watches.push(fn); - } -}; - angularService('$browser', function(){ return new MockBrowser(); }); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index a4afa21c..63c18700 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -188,5 +188,21 @@ describe("input widget", function(){ expect(element.hasClass('ng-exception')).toBeTruthy(); }); + it('should switch on value change', function(){ + compile('<ng:switch on="select"><div ng-switch-when="1">first</div><div ng-switch-when="2">second</div></ng:switch>'); + expect(element.html()).toEqual(''); + scope.select = 1; + scope.$eval(); + expect(element.text()).toEqual('first'); + scope.select = 2; + scope.$eval(); + expect(element.text()).toEqual('second'); + }); +}); +describe('ng:include', function(){ + it('should include on external file', function() { + var element = jqLite('<ng:include src="myUrl"></ng:include>'); + var scope = compile(element).$init(); + }); }); |
