diff options
Diffstat (limited to 'test/service')
| -rw-r--r-- | test/service/autoScrollSpec.js | 84 | ||||
| -rw-r--r-- | test/service/compilerSpec.js | 16 | ||||
| -rw-r--r-- | test/service/cookiesSpec.js | 4 | ||||
| -rw-r--r-- | test/service/deferSpec.js | 2 | ||||
| -rw-r--r-- | test/service/exceptionHandlerSpec.js | 12 | ||||
| -rw-r--r-- | test/service/filter/filtersSpec.js | 12 | ||||
| -rw-r--r-- | test/service/httpSpec.js | 131 | ||||
| -rw-r--r-- | test/service/locationSpec.js | 471 | ||||
| -rw-r--r-- | test/service/logSpec.js | 2 | ||||
| -rw-r--r-- | test/service/parseSpec.js | 11 | ||||
| -rw-r--r-- | test/service/scopeSpec.js | 59 |
11 files changed, 443 insertions, 361 deletions
diff --git a/test/service/autoScrollSpec.js b/test/service/autoScrollSpec.js index 8d04268b..86a47f50 100644 --- a/test/service/autoScrollSpec.js +++ b/test/service/autoScrollSpec.js @@ -53,7 +53,7 @@ describe('$autoScroll', function() { } - beforeEach(inject(function($provide) { + beforeEach(module(function($provide) { elmSpy = {}; $provide.value('$window', { scrollTo: jasmine.createSpy('$window.scrollTo'), @@ -108,11 +108,14 @@ describe('$autoScroll', function() { expectScrollingTo('id=top'))); - it('should not scroll when disabled', inject( - addElements('id=fake', 'a name=fake', 'input name=fake'), - disableScroller(), - changeHashAndScroll('fake'), - expectNoScrolling())); + it('should not scroll when disabled', function() { + module(disableScroller()); + inject( + addElements('id=fake', 'a name=fake', 'input name=fake'), + changeHashAndScroll('fake'), + expectNoScrolling() + ); + }); describe('watcher', function() { @@ -136,40 +139,57 @@ describe('$autoScroll', function() { })); - it('should scroll to element when hash change in hashbang mode', inject( - initLocation({html5Mode: false, historyApi: true}), - addElements('id=some'), - changeHashAndDigest('some'), - expectScrollingTo('id=some'))); + it('should scroll to element when hash change in hashbang mode', function() { + module(initLocation({html5Mode: false, historyApi: true})); + inject( + addElements('id=some'), + changeHashAndDigest('some'), + expectScrollingTo('id=some') + ); + }); - it('should scroll to element when hash change in html5 mode with no history api', inject( - initLocation({html5Mode: true, historyApi: false}), - addElements('id=some'), - changeHashAndDigest('some'), - expectScrollingTo('id=some'))); + it('should scroll to element when hash change in html5 mode with no history api', function() { + module(initLocation({html5Mode: true, historyApi: false})); + inject( + addElements('id=some'), + changeHashAndDigest('some'), + expectScrollingTo('id=some') + ); + }); - it('should not scroll when element does not exist', inject( - initLocation({html5Mode: false, historyApi: false}), - addElements('id=some'), - changeHashAndDigest('other'), - expectNoScrolling())); + it('should not scroll when element does not exist', function() { + module(initLocation({html5Mode: false, historyApi: false})); + inject( + addElements('id=some'), + changeHashAndDigest('other'), + expectNoScrolling() + ); + }); - it('should not scroll when html5 mode with history api', inject( - initLocation({html5Mode: true, historyApi: true}), - addElements('id=some'), - changeHashAndDigest('some'), - expectNoScrolling())); + it('should not scroll when html5 mode with history api', function() { + module(initLocation({html5Mode: true, historyApi: true})); + inject( + addElements('id=some'), + changeHashAndDigest('some'), + expectNoScrolling() + ); + }); - it('should not scroll when disabled', inject( - disableScroller(), - initLocation({html5Mode: false, historyApi: false}), - addElements('id=fake'), - changeHashAndDigest('fake'), - expectNoScrolling())); + it('should not scroll when disabled', function() { + module( + disableScroller(), + initLocation({html5Mode: false, historyApi: false}) + ); + inject( + addElements('id=fake'), + changeHashAndDigest('fake'), + expectNoScrolling() + ); + }); }); }); diff --git a/test/service/compilerSpec.js b/test/service/compilerSpec.js index ccf70aaf..6e6c211b 100644 --- a/test/service/compilerSpec.js +++ b/test/service/compilerSpec.js @@ -1,10 +1,10 @@ 'use strict'; describe('compiler', function() { - var compiler, textMmarkup, attrMarkup, directives, widgets, compile, log, $rootScope; + var textMarkup, attrMarkup, directives, widgets, compile, log; - beforeEach(inject(function($provide){ - textMmarkup = []; + beforeEach(module(function($provide){ + textMarkup = []; attrMarkup = []; widgets = extensionMap({}, 'widget'); directives = { @@ -26,7 +26,7 @@ describe('compiler', function() { }; log = ""; - $provide.value('$textMarkup', textMmarkup); + $provide.value('$textMarkup', textMarkup); $provide.value('$attrMarkup', attrMarkup); $provide.value('$directive', directives); $provide.value('$widget', widgets); @@ -138,7 +138,7 @@ describe('compiler', function() { it('should process markup before directives', inject(function($rootScope, $compile) { - textMmarkup.push(function(text, textNode, parentNode) { + textMarkup.push(function(text, textNode, parentNode) { if (text == 'middle') { expect(textNode.text()).toEqual(text); parentNode.attr('hello', text); @@ -176,7 +176,7 @@ describe('compiler', function() { this.directives(true); return noop; }; - textMmarkup.push(function(text, textNode, parent){ + textMarkup.push(function(text, textNode, parent){ if (text == '{{1+2}}') parent.text('3'); }); @@ -186,7 +186,7 @@ describe('compiler', function() { it('should allow multiple markups per text element', inject(function($rootScope, $compile) { - textMmarkup.push(function(text, textNode, parent){ + textMarkup.push(function(text, textNode, parent){ var index = text.indexOf('---'); if (index > -1) { textNode.after(text.substring(index + 3)); @@ -195,7 +195,7 @@ describe('compiler', function() { textNode.remove(); } }); - textMmarkup.push(function(text, textNode, parent){ + textMarkup.push(function(text, textNode, parent){ var index = text.indexOf('==='); if (index > -1) { textNode.after(text.substring(index + 3)); diff --git a/test/service/cookiesSpec.js b/test/service/cookiesSpec.js index d73923a6..5427ac36 100644 --- a/test/service/cookiesSpec.js +++ b/test/service/cookiesSpec.js @@ -1,13 +1,13 @@ 'use strict'; describe('$cookies', function() { - beforeEach(inject(function($provide) { + beforeEach(module(function($provide) { $provide.factory('$browser', function(){ return angular.extend(new angular.mock.$Browser(), {cookieHash: {preexisting:'oldCookie'}}); }); })); - + it('should provide access to existing cookies via object properties and keep them in sync', inject(function($cookies, $browser, $rootScope) { expect($cookies).toEqual({'preexisting': 'oldCookie'}); diff --git a/test/service/deferSpec.js b/test/service/deferSpec.js index e4554601..48c9e912 100644 --- a/test/service/deferSpec.js +++ b/test/service/deferSpec.js @@ -1,7 +1,7 @@ 'use strict'; describe('$defer', function() { - beforeEach(inject(function($provide) { + beforeEach(module(function($provide) { $provide.factory('$exceptionHandler', function(){ return jasmine.createSpy('$exceptionHandler'); }); diff --git a/test/service/exceptionHandlerSpec.js b/test/service/exceptionHandlerSpec.js index 00abff30..2f3d0e66 100644 --- a/test/service/exceptionHandlerSpec.js +++ b/test/service/exceptionHandlerSpec.js @@ -3,13 +3,13 @@ describe('$exceptionHandler', function() { - it('should log errors', inject( - function($provide){ + it('should log errors', function() { + module(function($provide){ $provide.service('$exceptionHandler', $ExceptionHandlerProvider); - }, - function($log, $exceptionHandler) { + }); + inject(function($log, $exceptionHandler) { $exceptionHandler('myError'); expect($log.error.logs.shift()).toEqual(['myError']); - } - )); + }); + }); }); diff --git a/test/service/filter/filtersSpec.js b/test/service/filter/filtersSpec.js index 40a78558..cc006447 100644 --- a/test/service/filter/filtersSpec.js +++ b/test/service/filter/filtersSpec.js @@ -8,13 +8,15 @@ describe('filters', function() { filter = $filter; })); - it('should called the filter when evaluating expression', inject(function($rootScope, $filterProvider) { + it('should call the filter when evaluating expression', function(){ var filter = jasmine.createSpy('myFilter'); - $filterProvider.register('myFilter', valueFn(filter)); - - $rootScope.$eval('10|myFilter'); + createInjector(['ng', function($filterProvider) { + $filterProvider.register('myFilter', valueFn(filter)); + }]).invoke(function($rootScope) { + $rootScope.$eval('10|myFilter'); + }); expect(filter).toHaveBeenCalledWith(10); - })); + }); describe('formatNumber', function() { var pattern; diff --git a/test/service/httpSpec.js b/test/service/httpSpec.js index 5efe2954..c6adee9e 100644 --- a/test/service/httpSpec.js +++ b/test/service/httpSpec.js @@ -1,20 +1,15 @@ 'use strict'; describe('$http', function() { - var $rootScope, callback; - beforeEach(inject( - function($exceptionHandlerProvider) { - $exceptionHandlerProvider.mode('log'); - }, - ['$rootScope', function($rs) { - $rootScope = $rs; - - spyOn($rootScope, '$apply').andCallThrough(); - callback = jasmine.createSpy('done'); - }] - )); + var callback; + beforeEach(function() { + callback = jasmine.createSpy('done'); + }); + beforeEach(module(function($exceptionHandlerProvider) { + $exceptionHandlerProvider.mode('log'); + })); afterEach(inject(function($exceptionHandler, $httpBackend) { forEach($exceptionHandler.errors, function(e) { @@ -33,73 +28,87 @@ describe('$http', function() { describe('interceptors', function() { - it('should default to an empty array', inject(function($httpProvider) { + it('should default to an empty array', module(function($httpProvider) { expect($httpProvider.responseInterceptors).toEqual([]); })); - it('should pass the responses through interceptors', inject(function($httpProvider, $q) { - // just change the response data and pass the response object along - $httpProvider.responseInterceptors.push(function(httpPromise) { - return httpPromise.then(function(response) { - response.data += '!'; - return response; + it('should pass the responses through interceptors', function() { + var shared = {}; + module(function($httpProvider, $provide) { + $provide.factory('testInterceptor', function ($q) { + return function(httpPromise) { + return httpPromise.then(function(response) { + var deferred = $q.defer(); + deferred.resolve({ + data: response.data + '?', + status: 209, + headers: response.headers, + config: response.config + }); + return deferred.promise; + }); + }; }); - }); - - // return a new resolved promise representing modified response object - $httpProvider.responseInterceptors.push(function(httpPromise) { - return httpPromise.then(function(response) { - var deferred = $q.defer(); - deferred.resolve({ - data: response.data + '?', - status: 209, - headers: response.headers, - config: response.config + // just change the response data and pass the response object along + $httpProvider.responseInterceptors.push(function(httpPromise) { + return httpPromise.then(function(response) { + response.data += '!'; + return response; }); - return deferred.promise; }); + + // return a new resolved promise representing modified response object + $httpProvider.responseInterceptors.push('testInterceptor'); }); - }, function($http, $httpBackend) { - $httpBackend.expect('GET', '/foo').respond(201, 'Hello'); - $http.get('/foo').success(function(data, status) { - expect(data).toBe('Hello!?'); - expect(status).toBe(209); - callback(); + inject(function($http, $httpBackend) { + $httpBackend.expect('GET', '/foo').respond(201, 'Hello'); + $http.get('/foo').success(function(data, status) { + expect(data).toBe('Hello!?'); + expect(status).toBe(209); + callback(); + }); + $httpBackend.flush(); + expect(callback).toHaveBeenCalledOnce(); }); - $httpBackend.flush(); - expect(callback).toHaveBeenCalledOnce(); - })); + }); - it('should support interceptors defined as services', inject( - function($provide, $httpProvider) { - $provide.factory('myInterceptor', function() { - return function(promise) { - return promise.then(function(response) { - response.data = uppercase(response.data); - return response; - }); - } - }); - $httpProvider.responseInterceptors.push('myInterceptor'); - }, function($http, $httpBackend) { - var response; + it('should support interceptors defined as services', function() { + module(function($provide, $httpProvider) { + $provide.factory('myInterceptor', function() { + return function(promise) { + return promise.then(function(response) { + response.data = uppercase(response.data); + return response; + }); + } + }); + $httpProvider.responseInterceptors.push('myInterceptor'); + }); + inject(function($http, $httpBackend) { + var response; - $httpBackend.expect('GET', '/test').respond('hello!'); - $http.get('/test').success(function(data) {response = data;}); - expect(response).toBeUndefined(); + $httpBackend.expect('GET', '/test').respond('hello!'); + $http.get('/test').success(function(data) {response = data;}); + expect(response).toBeUndefined(); - $httpBackend.flush(); - expect(response).toBe('HELLO!'); - } - )); + $httpBackend.flush(); + expect(response).toBe('HELLO!'); + }); + }); }); }); describe('the instance', function() { - var $httpBackend, $http; + var $httpBackend, $http, $rootScope; + + beforeEach(inject(['$rootScope', function($rs) { + $rootScope = $rs; + + spyOn($rootScope, '$apply').andCallThrough(); + }])); beforeEach(inject(['$httpBackend', '$http', function($hb, $h) { $httpBackend = $hb; diff --git a/test/service/locationSpec.js b/test/service/locationSpec.js index 7c075fc0..c7cc9c23 100644 --- a/test/service/locationSpec.js +++ b/test/service/locationSpec.js @@ -335,11 +335,11 @@ describe('$location', function() { function initService(html5Mode, hashPrefix, supportHistory) { - return function($provide, $locationProvider){ + return module(function($provide, $locationProvider){ $locationProvider.html5Mode(html5Mode); $locationProvider.hashPrefix(hashPrefix); $provide.value('$sniffer', {history: supportHistory}); - }; + }); } function initBrowser(url, basePath) { return function($browser){ @@ -350,7 +350,8 @@ describe('$location', function() { describe('wiring', function() { - beforeEach(inject(initService(false, '!', true), initBrowser('http://new.com/a/b#!', '/a/b'))); + beforeEach(initService(false, '!', true)); + beforeEach(inject(initBrowser('http://new.com/a/b#!', '/a/b'))); it('should update $location when browser url changes', inject(function($browser, $location) { @@ -413,30 +414,34 @@ describe('$location', function() { // html5 history is disabled describe('disabled history', function() { - it('should use hashbang url with hash prefix', inject( - initService(false, '!'), - initBrowser('http://domain.com/base/index.html#!/a/b', '/base/index.html'), - function($rootScope, $location, $browser) { - expect($browser.url()).toBe('http://domain.com/base/index.html#!/a/b'); - $location.path('/new'); - $location.search({a: true}); - $rootScope.$apply(); - expect($browser.url()).toBe('http://domain.com/base/index.html#!/new?a'); - }) - ); - - - it('should use hashbang url without hash prefix', inject( - initService(false, ''), - initBrowser('http://domain.com/base/index.html#/a/b', '/base/index.html'), - function($rootScope, $location, $browser) { - expect($browser.url()).toBe('http://domain.com/base/index.html#/a/b'); - $location.path('/new'); - $location.search({a: true}); - $rootScope.$apply(); - expect($browser.url()).toBe('http://domain.com/base/index.html#/new?a'); - }) - ); + it('should use hashbang url with hash prefix', function() { + initService(false, '!'); + inject( + initBrowser('http://domain.com/base/index.html#!/a/b', '/base/index.html'), + function($rootScope, $location, $browser) { + expect($browser.url()).toBe('http://domain.com/base/index.html#!/a/b'); + $location.path('/new'); + $location.search({a: true}); + $rootScope.$apply(); + expect($browser.url()).toBe('http://domain.com/base/index.html#!/new?a'); + } + ); + }); + + + it('should use hashbang url without hash prefix', function() { + initService(false, ''); + inject( + initBrowser('http://domain.com/base/index.html#/a/b', '/base/index.html'), + function($rootScope, $location, $browser) { + expect($browser.url()).toBe('http://domain.com/base/index.html#/a/b'); + $location.path('/new'); + $location.search({a: true}); + $rootScope.$apply(); + expect($browser.url()).toBe('http://domain.com/base/index.html#/new?a'); + } + ); + }); }); @@ -447,26 +452,30 @@ describe('$location', function() { dealoc($document); })); - it('should use hashbang url with hash prefix', inject( - initService(true, '!!', false), - initBrowser('http://domain.com/base/index.html#!!/a/b', '/base/index.html'), - function($rootScope, $location, $browser) { - expect($browser.url()).toBe('http://domain.com/base/index.html#!!/a/b'); - $location.path('/new'); - $location.search({a: true}); - $rootScope.$apply(); - expect($browser.url()).toBe('http://domain.com/base/index.html#!!/new?a'); - }) - ); - - - it('should redirect to hashbang url when new url given', inject( - initService(true, '!'), - initBrowser('http://domain.com/base/new-path/index.html', '/base/index.html'), - function($browser, $location) { - expect($browser.url()).toBe('http://domain.com/base/index.html#!/new-path/index.html'); - }) - ); + it('should use hashbang url with hash prefix', function() { + initService(true, '!!', false); + inject( + initBrowser('http://domain.com/base/index.html#!!/a/b', '/base/index.html'), + function($rootScope, $location, $browser) { + expect($browser.url()).toBe('http://domain.com/base/index.html#!!/a/b'); + $location.path('/new'); + $location.search({a: true}); + $rootScope.$apply(); + expect($browser.url()).toBe('http://domain.com/base/index.html#!!/new?a'); + } + ); + }); + + + it('should redirect to hashbang url when new url given', function() { + initService(true, '!'); + inject( + initBrowser('http://domain.com/base/new-path/index.html', '/base/index.html'), + function($browser, $location) { + expect($browser.url()).toBe('http://domain.com/base/index.html#!/new-path/index.html'); + } + ); + }); }); @@ -477,41 +486,47 @@ describe('$location', function() { dealoc($document); })); - it('should use new url', inject( - initService(true, '', true), - initBrowser('http://domain.com/base/old/index.html#a', '/base/index.html'), - function($rootScope, $location, $browser) { - expect($browser.url()).toBe('http://domain.com/base/old/index.html#a'); - $location.path('/new'); - $location.search({a: true}); - $rootScope.$apply(); - expect($browser.url()).toBe('http://domain.com/base/new?a#a'); - }) - ); - - - it('should rewrite when hashbang url given', inject( - initService(true, '!', true), - initBrowser('http://domain.com/base/index.html#!/a/b', '/base/index.html'), - function($rootScope, $location, $browser) { - expect($browser.url()).toBe('http://domain.com/base/a/b'); - $location.path('/new'); - $location.hash('abc'); - $rootScope.$apply(); - expect($browser.url()).toBe('http://domain.com/base/new#abc'); - expect($location.path()).toBe('/new'); - }) - ); - - - it('should rewrite when hashbang url given (without hash prefix)', inject( - initService(true, '', true), - initBrowser('http://domain.com/base/index.html#/a/b', '/base/index.html'), - function($rootScope, $location, $browser) { - expect($browser.url()).toBe('http://domain.com/base/a/b'); - expect($location.path()).toBe('/a/b'); - }) - ); + it('should use new url', function() { + initService(true, '', true); + inject( + initBrowser('http://domain.com/base/old/index.html#a', '/base/index.html'), + function($rootScope, $location, $browser) { + expect($browser.url()).toBe('http://domain.com/base/old/index.html#a'); + $location.path('/new'); + $location.search({a: true}); + $rootScope.$apply(); + expect($browser.url()).toBe('http://domain.com/base/new?a#a'); + } + ); + }); + + + it('should rewrite when hashbang url given', function() { + initService(true, '!', true); + inject( + initBrowser('http://domain.com/base/index.html#!/a/b', '/base/index.html'), + function($rootScope, $location, $browser) { + expect($browser.url()).toBe('http://domain.com/base/a/b'); + $location.path('/new'); + $location.hash('abc'); + $rootScope.$apply(); + expect($browser.url()).toBe('http://domain.com/base/new#abc'); + expect($location.path()).toBe('/new'); + } + ); + }); + + + it('should rewrite when hashbang url given (without hash prefix)', function() { + initService(true, '', true); + inject( + initBrowser('http://domain.com/base/index.html#/a/b', '/base/index.html'), + function($rootScope, $location, $browser) { + expect($browser.url()).toBe('http://domain.com/base/a/b'); + expect($location.path()).toBe('/a/b'); + } + ); + }); }); @@ -604,7 +619,7 @@ describe('$location', function() { var root, link, originalBrowser, lastEventPreventDefault; function configureService(linkHref, html5Mode, supportHist, attrs, content) { - return function($provide, $locationProvider){ + module(function($provide, $locationProvider) { var jqRoot = jqLite('<div></div>'); attrs = attrs ? ' ' + attrs + ' ' : ''; link = jqLite('<a href="' + linkHref + '"' + attrs + '>' + content + '</a>')[0]; @@ -616,7 +631,7 @@ describe('$location', function() { $provide.value('$sniffer', {history: supportHist}); $locationProvider.html5Mode(html5Mode); $locationProvider.hashPrefix('!'); - }; + }); } function initBrowser() { @@ -654,152 +669,178 @@ describe('$location', function() { }); - it('should rewrite rel link to new url when history enabled on new browser', inject( - configureService('link?a#b', true, true), - initBrowser(), - initLocation(), - function($browser) { - browserTrigger(link, 'click'); - expectRewriteTo($browser, 'http://host.com/base/link?a#b'); - }) - ); - - - it('should rewrite abs link to new url when history enabled on new browser', inject( - configureService('/base/link?a#b', true, true), - initBrowser(), - initLocation(), - function($browser) { - browserTrigger(link, 'click'); - expectRewriteTo($browser, 'http://host.com/base/link?a#b'); - }) - ); - - - it('should rewrite rel link to hashbang url when history enabled on old browser', inject( - configureService('link?a#b', true, false), - initBrowser(), - initLocation(), - function($browser) { - browserTrigger(link, 'click'); - expectRewriteTo($browser, 'http://host.com/base/index.html#!/link?a#b'); - }) - ); - - - it('should rewrite abs link to hashbang url when history enabled on old browser', inject( - configureService('/base/link?a#b', true, false), - initBrowser(), - initLocation(), - function($browser) { - browserTrigger(link, 'click'); - expectRewriteTo($browser, 'http://host.com/base/index.html#!/link?a#b'); - }) - ); - - - it('should not rewrite when history disabled', inject( - configureService('#new', false), - initBrowser(), - initLocation(), - function($browser) { - browserTrigger(link, 'click'); - expectNoRewrite($browser); - }) - ); - - - it('should not rewrite ng:ext-link', inject( - configureService('#new', true, true, 'ng:ext-link'), - initBrowser(), - initLocation(), - function($browser) { - browserTrigger(link, 'click'); - expectNoRewrite($browser); - }) - ); - - - it('should not rewrite full url links do different domain', inject( - configureService('http://www.dot.abc/a?b=c', true), - initBrowser(), - initLocation(), - function($browser) { - browserTrigger(link, 'click'); - expectNoRewrite($browser); - }) - ); - - - it('should not rewrite links with target="_blank"', inject( - configureService('/a?b=c', true, true, 'target="_blank"'), - initBrowser(), - initLocation(), - function($browser) { - browserTrigger(link, 'click'); - expectNoRewrite($browser); - }) - ); - - - it('should not rewrite links with target specified', inject( - configureService('/a?b=c', true, true, 'target="some-frame"'), - initBrowser(), - initLocation(), - function($browser) { - browserTrigger(link, 'click'); - expectNoRewrite($browser); - }) - ); - - - it('should rewrite full url links to same domain and base path', inject( - configureService('http://host.com/base/new', true), - initBrowser(), - initLocation(), - function($browser) { - browserTrigger(link, 'click'); - expectRewriteTo($browser, 'http://host.com/base/index.html#!/new'); - }) - ); - - - it('should rewrite when clicked span inside link', inject( - configureService('some/link', true, true, '', '<span>link</span>'), - initBrowser(), - initLocation(), - function($browser) { - var span = jqLite(link).find('span'); - - browserTrigger(span, 'click'); - expectRewriteTo($browser, 'http://host.com/base/some/link'); - }) - ); + it('should rewrite rel link to new url when history enabled on new browser', function() { + configureService('link?a#b', true, true); + inject( + initBrowser(), + initLocation(), + function($browser) { + browserTrigger(link, 'click'); + expectRewriteTo($browser, 'http://host.com/base/link?a#b'); + } + ); + }); - // don't run next tests on IE<9, as browserTrigger does not simulate pressed keys - if (!(msie < 9)) { + it('should rewrite abs link to new url when history enabled on new browser', function() { + configureService('/base/link?a#b', true, true); + inject( + initBrowser(), + initLocation(), + function($browser) { + browserTrigger(link, 'click'); + expectRewriteTo($browser, 'http://host.com/base/link?a#b'); + } + ); + }); + - it('should not rewrite when clicked with ctrl pressed', inject( - configureService('/a?b=c', true, true), + it('should rewrite rel link to hashbang url when history enabled on old browser', function() { + configureService('link?a#b', true, false); + inject( initBrowser(), initLocation(), function($browser) { - browserTrigger(link, 'click', ['ctrl']); + browserTrigger(link, 'click'); + expectRewriteTo($browser, 'http://host.com/base/index.html#!/link?a#b'); + } + ); + }); + + + it('should rewrite abs link to hashbang url when history enabled on old browser', function() { + configureService('/base/link?a#b', true, false); + inject( + initBrowser(), + initLocation(), + function($browser) { + browserTrigger(link, 'click'); + expectRewriteTo($browser, 'http://host.com/base/index.html#!/link?a#b'); + } + ); + }); + + + it('should not rewrite when history disabled', function() { + configureService('#new', false); + inject( + initBrowser(), + initLocation(), + function($browser) { + browserTrigger(link, 'click'); + expectNoRewrite($browser); + } + ); + }); + + + it('should not rewrite ng:ext-link', function() { + configureService('#new', true, true, 'ng:ext-link'); + inject( + initBrowser(), + initLocation(), + function($browser) { + browserTrigger(link, 'click'); + expectNoRewrite($browser); + } + ); + }); + + + it('should not rewrite full url links do different domain', function() { + configureService('http://www.dot.abc/a?b=c', true); + inject( + initBrowser(), + initLocation(), + function($browser) { + browserTrigger(link, 'click'); expectNoRewrite($browser); - }) + } ); + }); + + + it('should not rewrite links with target="_blank"', function() { + configureService('/a?b=c', true, true, 'target="_blank"'); + inject( + initBrowser(), + initLocation(), + function($browser) { + browserTrigger(link, 'click'); + expectNoRewrite($browser); + } + ); + }); - it('should not rewrite when clicked with meta pressed', inject( - configureService('/a?b=c', true, true), + it('should not rewrite links with target specified', function() { + configureService('/a?b=c', true, true, 'target="some-frame"'); + inject( initBrowser(), initLocation(), function($browser) { - browserTrigger(link, 'click', ['meta']); + browserTrigger(link, 'click'); expectNoRewrite($browser); - }) + } ); + }); + + + it('should rewrite full url links to same domain and base path', function() { + configureService('http://host.com/base/new', true); + inject( + initBrowser(), + initLocation(), + function($browser) { + browserTrigger(link, 'click'); + expectRewriteTo($browser, 'http://host.com/base/index.html#!/new'); + } + ); + }); + + + it('should rewrite when clicked span inside link', function() { + configureService('some/link', true, true, '', '<span>link</span>'); + inject( + initBrowser(), + initLocation(), + function($browser) { + var span = jqLite(link).find('span'); + + browserTrigger(span, 'click'); + expectRewriteTo($browser, 'http://host.com/base/some/link'); + } + ); + }); + + + // don't run next tests on IE<9, as browserTrigger does not simulate pressed keys + if (!(msie < 9)) { + + it('should not rewrite when clicked with ctrl pressed', function() { + configureService('/a?b=c', true, true); + inject( + initBrowser(), + initLocation(), + function($browser) { + browserTrigger(link, 'click', ['ctrl']); + expectNoRewrite($browser); + } + ); + }); + + + it('should not rewrite when clicked with meta pressed', function() { + configureService('/a?b=c', true, true); + inject( + initBrowser(), + initLocation(), + function($browser) { + browserTrigger(link, 'click', ['meta']); + expectNoRewrite($browser); + } + ); + }); } }); }); diff --git a/test/service/logSpec.js b/test/service/logSpec.js index ee250b66..98158ae0 100644 --- a/test/service/logSpec.js +++ b/test/service/logSpec.js @@ -9,7 +9,7 @@ describe('$log', function() { function info() { logger+= 'info;'; } function error() { logger+= 'error;'; } - beforeEach(inject(function($provide){ + beforeEach(module(function($provide){ $window = {}; logger = ''; $provide.service('$log', $LogProvider); diff --git a/test/service/parseSpec.js b/test/service/parseSpec.js index f57a52c7..08167843 100644 --- a/test/service/parseSpec.js +++ b/test/service/parseSpec.js @@ -154,7 +154,10 @@ describe('parser', function() { }); }); - var scope; + var scope, $filterProvider; + beforeEach(module(['$filterProvider', function (filterProvider) { + $filterProvider = filterProvider; + }])); beforeEach(inject(function ($rootScope) { scope = $rootScope; })); @@ -191,19 +194,19 @@ describe('parser', function() { expect(scope.$eval("'a' + 'b c'")).toEqual("ab c"); }); - it('should parse filters', inject(function($filterProvider) { + it('should parse filters', function() { $filterProvider.register('substring', valueFn(function(input, start, end) { return input.substring(start, end); })); expect(function() { scope.$eval("1|nonexistent"); - }).toThrow(new Error("Unknown provider for 'nonexistentFilter'.")); + }).toThrow(new Error("Unknown provider: nonexistentFilterProvider <- nonexistentFilter")); scope.offset = 3; expect(scope.$eval("'abcd'|substring:1:offset")).toEqual("bc"); expect(scope.$eval("'abcd'|substring:1:3|uppercase")).toEqual("BC"); - })); + }); it('should access scope', function() { scope.a = 123; diff --git a/test/service/scopeSpec.js b/test/service/scopeSpec.js index e1e8ab8b..96271bc9 100644 --- a/test/service/scopeSpec.js +++ b/test/service/scopeSpec.js @@ -117,15 +117,18 @@ describe('Scope', function() { })); - it('should delegate exceptions', inject(function($exceptionHandlerProvider) { - $exceptionHandlerProvider.mode('log'); - }, function($rootScope, $exceptionHandler, $log) { - $rootScope.$watch('a', function() {throw new Error('abc');}); - $rootScope.a = 1; - $rootScope.$digest(); - expect($exceptionHandler.errors[0].message).toEqual('abc'); - $log.assertEmpty(); - })); + it('should delegate exceptions', function() { + module(function($exceptionHandlerProvider) { + $exceptionHandlerProvider.mode('log'); + }); + inject(function($rootScope, $exceptionHandler, $log) { + $rootScope.$watch('a', function() {throw new Error('abc');}); + $rootScope.a = 1; + $rootScope.$digest(); + expect($exceptionHandler.errors[0].message).toEqual('abc'); + $log.assertEmpty(); + }); + }); it('should fire watches in order of addition', inject(function($rootScope) { @@ -459,25 +462,29 @@ describe('Scope', function() { })); - it('should catch exceptions', inject(function($exceptionHandlerProvider) { + it('should catch exceptions', function() { + module(function($exceptionHandlerProvider) { $exceptionHandlerProvider.mode('log'); - }, function($rootScope, $exceptionHandler, $log) { - var log = ''; - var child = $rootScope.$new(); - $rootScope.$watch('a', function(scope, a) { log += '1'; }); - $rootScope.a = 0; - child.$apply(function() { throw new Error('MyError'); }); - expect(log).toEqual('1'); - expect($exceptionHandler.errors[0].message).toEqual('MyError'); - $log.error.logs.shift(); - })); + }); + inject(function($rootScope, $exceptionHandler, $log) { + var log = ''; + var child = $rootScope.$new(); + $rootScope.$watch('a', function(scope, a) { log += '1'; }); + $rootScope.a = 0; + child.$apply(function() { throw new Error('MyError'); }); + expect(log).toEqual('1'); + expect($exceptionHandler.errors[0].message).toEqual('MyError'); + $log.error.logs.shift(); + }); + }); describe('exceptions', function() { var log; - beforeEach(inject(function($exceptionHandlerProvider) { - $exceptionHandlerProvider.mode('log'); - }, function($rootScope) { + beforeEach(module(function($exceptionHandlerProvider) { + $exceptionHandlerProvider.mode('log'); + })); + beforeEach(inject(function($rootScope) { log = ''; $rootScope.$watch(function() { log += '$digest;'; }); $rootScope.$digest(); @@ -613,10 +620,10 @@ describe('Scope', function() { log += event.currentScope.id + '>'; } - beforeEach(inject( - function($exceptionHandlerProvider) { + beforeEach(module(function($exceptionHandlerProvider) { $exceptionHandlerProvider.mode('log'); - }, function($rootScope) { + })); + beforeEach(inject(function($rootScope) { log = ''; child = $rootScope.$new(); grandChild = child.$new(); |
