diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/AngularTest.js | 44 | ||||
| -rw-r--r-- | test/BinderTest.js | 38 | ||||
| -rw-r--r-- | test/ScopeSpec.js | 44 | ||||
| -rw-r--r-- | test/UrlWatcherTest.js | 25 | ||||
| -rw-r--r-- | test/servicesSpec.js | 27 |
5 files changed, 112 insertions, 66 deletions
diff --git a/test/AngularTest.js b/test/AngularTest.js deleted file mode 100644 index 8db723e5..00000000 --- a/test/AngularTest.js +++ /dev/null @@ -1,44 +0,0 @@ -AngularTest = TestCase('AngularTest'); - -UrlWatcherTest = TestCase('UrlWatcherTest'); - -UrlWatcherTest.prototype.testUrlWatcher = function () { - expectAsserts(2); - var location = {href:"http://server", hash:""}; - var watcher = new UrlWatcher(location); - watcher.delay = 1; - watcher.listener = function(url){ - assertEquals('http://getangular.test', url); - }; - watcher.setTimeout = function(fn, delay){ - assertEquals(1, delay); - location.href = "http://getangular.test"; - watcher.setTimeout = function(fn, delay) { - }; - fn(); - }; - watcher.watch(); -}; - -UrlWatcherTest.prototype.testItShouldFireOnUpdateEventWhenSpecialURLSet = function(){ - expectAsserts(2); - var location = {href:"http://server", hash:"#$iframe_notify=1234"}; - var watcher = new UrlWatcher(location); - angular.callbacks._iframe_notify_1234 = function () { - assertEquals("undefined", typeof angularCallbacks._iframe_notify_1234); - assertEquals("http://server2#", location.href); - }; - watcher.delay = 1; - watcher.expectedUrl = "http://server2"; - watcher.setTimeout = function(fn, delay){ - watcher.setTimeout = function(fn, delay) {}; - fn(); - }; - watcher.watch(); -}; - -FunctionTest = TestCase("FunctionTest"); - -FunctionTest.prototype.testEscapeHtml = function () { - assertEquals("<div>&amp;</div>", escapeHtml('<div>&</div>')); -}; diff --git a/test/BinderTest.js b/test/BinderTest.js index 4d996a8e..67800e62 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -201,24 +201,6 @@ BinderTest.prototype.XtestParseAnchor = function(){ assertTrue(!binder.anchor.x); }; -BinderTest.prototype.XtestWriteAnchor = function(){ - var binder = this.compile("<div/>").binder; - binder.location.set('a'); - binder.anchor.a = 'b'; - binder.anchor.c = ' '; - binder.anchor.d = true; - binder.updateAnchor(); - assertEquals(binder.location.get(), "a#a=b&c=%20&d"); -}; - -BinderTest.prototype.XtestWriteAnchorAsPartOfTheUpdateView = function(){ - var binder = this.compile("<div/>").binder; - binder.location.set('a'); - binder.anchor.a = 'b'; - binder.updateView(); - assertEquals(binder.location.get(), "a#a=b"); -}; - BinderTest.prototype.testRepeaterUpdateBindings = function(){ var a = this.compile('<ul><LI ng-repeat="item in model.items" ng-bind="item.a"/></ul>'); var form = a.node; @@ -821,3 +803,23 @@ BinderTest.prototype.testItShouldUseFormaterForText = function() { x.scope.$eval(); assertEquals('1, 2, 3', input[0].value); }; + +BinderTest.prototype.XtestWriteAnchor = function(){ + var binder = this.compile("<div/>").binder; + binder.location.set('a'); + binder.anchor.a = 'b'; + binder.anchor.c = ' '; + binder.anchor.d = true; + binder.updateAnchor(); + assertEquals(binder.location.get(), "a#a=b&c=%20&d"); +}; + +BinderTest.prototype.XtestWriteAnchorAsPartOfTheUpdateView = function(){ + var binder = this.compile("<div/>").binder; + binder.location.set('a'); + binder.anchor.a = 'b'; + binder.updateView(); + assertEquals(binder.location.get(), "a#a=b"); +}; + + diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js index 7e1a899f..8d2a0ed4 100644 --- a/test/ScopeSpec.js +++ b/test/ScopeSpec.js @@ -11,7 +11,8 @@ describe('scope/model', function(){ model.$set('name', 'adam'); expect(model.name).toEqual('adam'); expect(model.$get('name')).toEqual('adam'); - expect(model.$parent).toEqual(parent); + expect(model.$parent).toEqual(model); + expect(model.$root).toEqual(model); }); //$eval @@ -78,15 +79,50 @@ describe('scope/model', function(){ expect(model.printed).toEqual(true); }); - - //$tryEval it('should report error on element', function(){ - + var scope = createScope(); + scope.$tryEval('throw "myerror";', function(error){ + scope.error = error; + }); + expect(scope.error).toEqual('myerror'); }); it('should report error on visible element', function(){ + var element = jqLite('<div></div>'); + var scope = createScope(); + scope.$tryEval('throw "myError"', element); + expect(element.attr('ng-error')).toEqual('"myError"'); // errors are jsonified + expect(element.hasClass('ng-exception')).toBeTruthy(); + }); + + // $onEval + + it("should eval using priority", function(){ + var scope = createScope(); + scope.log = ""; + scope.$onEval('log = log + "middle;"'); + scope.$onEval(-1, 'log = log + "first;"'); + scope.$onEval(1, 'log = log + "last;"'); + scope.$eval(); + expect(scope.log).toEqual('first;middle;last;'); + }); + + // Services are initialized + it("should inject services", function(){ + var scope = createScope(serviceAdapter({ + $window: function(){ + return window; + } + })); + expect(scope.$window).toEqual(window); + }); + it("should have $root and $parent", function(){ + var parent = createScope(); + var scope = createScope(parent); + expect(scope.$root).toEqual(parent); + expect(scope.$parent).toEqual(parent); }); }); diff --git a/test/UrlWatcherTest.js b/test/UrlWatcherTest.js new file mode 100644 index 00000000..6080ca62 --- /dev/null +++ b/test/UrlWatcherTest.js @@ -0,0 +1,25 @@ +UrlWatcherTest = TestCase('UrlWatcherTest'); + +UrlWatcherTest.prototype.testUrlWatcher = function () { + expectAsserts(2); + var location = {href:"http://server", hash:""}; + var watcher = new UrlWatcher(location); + watcher.delay = 1; + watcher.watch(function(url){ + assertEquals('http://getangular.test', url); + }); + watcher.setTimeout = function(fn, delay){ + assertEquals(1, delay); + location.href = "http://getangular.test"; + watcher.setTimeout = function(fn, delay) { + }; + fn(); + }; + watcher.start(); +}; + +FunctionTest = TestCase("FunctionTest"); + +FunctionTest.prototype.testEscapeHtml = function () { + assertEquals("<div>&amp;</div>", escapeHtml('<div>&</div>')); +}; diff --git a/test/servicesSpec.js b/test/servicesSpec.js new file mode 100644 index 00000000..5a6bcedc --- /dev/null +++ b/test/servicesSpec.js @@ -0,0 +1,27 @@ +describe("services", function(){ + var scope; + + beforeEach(function(){ + scope = createScope({ + $config: { + 'location': {'get':noop, 'set':noop, 'watch':noop} + } + }, serviceAdapter(angularService)); + }); + + it("should inject $window", function(){ + expect(scope.$window).toEqual(window); + }); + + it("should inject $anchor", function(){ + scope.$anchor('#path?key=value'); + expect(scope.$anchor.path).toEqual("path"); + expect(scope.$anchor.param).toEqual({key:'value'}); + + scope.$anchor.path = 'page=http://path'; + scope.$anchor.param = {k:'a=b'}; + + expect(scope.$anchor()).toEqual('page=http://path?k=a%3Db'); + + }); +}); |
