diff --git a/Gruntfile.js b/Gruntfile.js index 95c5167dbde2..170f494afc6d 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -107,6 +107,9 @@ module.exports = function(grunt) { options: { jshintrc: true, }, + tests: { + files: { src: 'test/**/*.js' }, + }, ng: { files: { src: files['angularSrc'] }, }, diff --git a/test/.jshintrc b/test/.jshintrc index f369426120d1..fe91f7f29e2b 100644 --- a/test/.jshintrc +++ b/test/.jshintrc @@ -16,6 +16,7 @@ "sub": true, "undef": true, "browser": true, + "indent": 2, "globals": { /* auto/injector.js */ "createInjector": false, @@ -42,7 +43,6 @@ "isArrayLike": false, "forEach": false, "sortedKeys": false, - "forEachSorted": false, "reverseParams": false, "nextUid": false, "setHashKey": false, @@ -102,9 +102,6 @@ "getter": false, "getBlockElements": false, - /* filters.js */ - "getFirstThursdayOfYear": false, - /* AngularPublic.js */ "version": false, "publishExternalAPI": false, @@ -147,24 +144,6 @@ "urlResolve": false, "urlIsSameOrigin": false, - /* ng/compile.js */ - "directiveNormalize": false, - - /* ng/parse.js */ - "setter": false, - - /* ng/directive/directives.js */ - "ngDirective": false, - - /* ng/directive/input.js */ - "VALID_CLASS": false, - "INVALID_CLASS": false, - "PRISTINE_CLASS": false, - "DIRTY_CLASS": false, - - /* ng/directive/form.js */ - "nullFormCtrl": false, - /* jasmine / karma */ "it": false, "iit": false, @@ -175,10 +154,29 @@ "expect": false, "jasmine": false, "spyOn": false, + "waits": false, + "waitsFor": false, + "runs": false, + "dump": false, + + /* e2e */ + "browser": false, + "element": false, + "by": false, /* testabilityPatch / matchers */ "inject": false, "module": false, - "dealoc": false + "dealoc": false, + "_jQuery": false, + "_jqLiteMode": false, + "sortedHtml": false, + "childrenTagsOf": false, + "assertHidden": false, + "assertVisible": false, + "provideLog": false, + "spyOnlyCallsWithArgs": false, + "createMockStyleSheet": false, + "browserTrigger": false } } diff --git a/test/AngularSpec.js b/test/AngularSpec.js index f1b0b7203abb..12142a918fc1 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -118,7 +118,7 @@ describe('angular', function() { it('should throw an exception when source and destination are equivalent', function() { var src, dst; - src = dst = {key: 'value'}; + src = dst = {key: 'value'}; expect(function() { copy(src, dst); }).toThrowMinErr("ng", "cpi", "Can't copy! Source and destination are identical."); src = dst = [2, 4]; expect(function() { copy(src, dst); }).toThrowMinErr("ng", "cpi", "Can't copy! Source and destination are identical."); @@ -149,7 +149,6 @@ describe('angular', function() { }); describe("extend", function() { - it('should not copy the private $$hashKey', function() { var src,dst; src = {}; @@ -209,7 +208,7 @@ describe('angular', function() { it('should omit properties from prototype chain', function() { var original, clone = {}; - function Func() {}; + function Func() {} Func.prototype.hello = "world"; original = new Func(); @@ -316,6 +315,7 @@ describe('angular', function() { }); it('should correctly test for keys that are present on Object.prototype', function() { + /* jshint -W001 */ // MS IE8 just doesn't work for this kind of thing, since "for ... in" doesn't return // things like hasOwnProperty even if it is explicitly defined on the actual object! if (msie<=8) return; @@ -457,7 +457,7 @@ describe('angular', function() { expect(toKeyValue({key: [323,'value',true]})).toEqual('key=323&key=value&key'); expect(toKeyValue({key: [323,'value',true, 1234]})). toEqual('key=323&key=value&key&key=1234'); - }); + }); }); @@ -472,13 +472,14 @@ describe('angular', function() { var obj = new MyObj(), log = []; - forEach(obj, function(value, key) { log.push(key + ':' + value)}); + forEach(obj, function(value, key) { log.push(key + ':' + value); }); expect(log).toEqual(['bar:barVal', 'baz:bazVal']); }); it('should not break if obj is an array we override hasOwnProperty', function() { + /* jshint -W001 */ var obj = []; obj[0] = 1; obj[1] = 2; @@ -506,7 +507,7 @@ describe('angular', function() { log = []; - forEach(nodeList, function(value, key) { log.push(key + ':' + value.innerHTML)}); + forEach(nodeList, function(value, key) { log.push(key + ':' + value.innerHTML); }); expect(log).toEqual(['0:a', '1:b', '2:c']); }); @@ -521,7 +522,7 @@ describe('angular', function() { var htmlCollection = document.getElementsByName('x'), log = []; - forEach(htmlCollection, function(value, key) { log.push(key + ':' + value.innerHTML)}); + forEach(htmlCollection, function(value, key) { log.push(key + ':' + value.innerHTML); }); expect(log).toEqual(['0:a', '1:c']); }); @@ -536,7 +537,7 @@ describe('angular', function() { var htmlCollection = document.querySelectorAll('[name="x"]'), log = []; - forEach(htmlCollection, function(value, key) { log.push(key + ':' + value.innerHTML)}); + forEach(htmlCollection, function(value, key) { log.push(key + ':' + value.innerHTML); }); expect(log).toEqual(['0:a', '1:c']); }); } @@ -545,28 +546,28 @@ describe('angular', function() { var args, log = []; - (function(){ args = arguments}('a', 'b', 'c')); + (function(){ args = arguments; }('a', 'b', 'c')); - forEach(args, function(value, key) { log.push(key + ':' + value)}); + forEach(args, function(value, key) { log.push(key + ':' + value); }); expect(log).toEqual(['0:a', '1:b', '2:c']); }); it('should handle string values like arrays', function() { var log = []; - forEach('bar', function(value, key) { log.push(key + ':' + value)}); + forEach('bar', function(value, key) { log.push(key + ':' + value); }); expect(log).toEqual(['0:b', '1:a', '2:r']); }); it('should handle objects with length property as objects', function() { var obj = { - 'foo' : 'bar', - 'length': 2 - }, - log = []; + 'foo' : 'bar', + 'length': 2 + }, + log = []; - forEach(obj, function(value, key) { log.push(key + ':' + value)}); + forEach(obj, function(value, key) { log.push(key + ':' + value); }); expect(log).toEqual(['foo:bar', 'length:2']); }); @@ -574,13 +575,13 @@ describe('angular', function() { it('should handle objects of custom types with length property as objects', function() { function CustomType() { this.length = 2; - this.foo = 'bar' + this.foo = 'bar'; } var obj = new CustomType(), log = []; - forEach(obj, function(value, key) { log.push(key + ':' + value)}); + forEach(obj, function(value, key) { log.push(key + ':' + value); }); expect(log).toEqual(['length:2', 'foo:bar']); }); }); @@ -748,9 +749,11 @@ describe('angular', function() { var appElement = jqLite('
')[0]; expect(function() { - angularInit(appElement, bootstrap); + angularInit(appElement, angular.bootstrap); }).toThrowMatching( - /\[\$injector:modulerr] Failed to instantiate module doesntexist due to:\n.*\[\$injector:nomod] Module 'doesntexist' is not available! You either misspelled the module name or forgot to load it\./ + new RegExp('\\[\\$injector:modulerr] Failed to instantiate module doesntexist due to:\\n' + + '.*\\[\\$injector:nomod] Module \'doesntexist\' is not available! You either ' + + 'misspelled the module name or forgot to load it\\.') ); }); @@ -789,7 +792,7 @@ describe('angular', function() { expect(bootstrapSpy.mostRecentCall.args[2].strictDi).toBe(true); var injector = appElement.injector(); - function testFactory($rootScope) {}; + function testFactory($rootScope) {} expect(function() { injector.instantiate(testFactory); }).toThrowMinErr('$injector', 'strictdi'); @@ -956,7 +959,9 @@ describe('angular', function() { expect(function() { angular.bootstrap(element, ['doesntexist']); }).toThrowMatching( - /\[\$injector:modulerr\] Failed to instantiate module doesntexist due to:\n.*\[\$injector:nomod\] Module 'doesntexist' is not available! You either misspelled the module name or forgot to load it\./); + new RegExp('\\[\\$injector:modulerr\\] Failed to instantiate module doesntexist due to:\\n' + + '.*\\[\\$injector:nomod\\] Module \'doesntexist\' is not available! You either ' + + 'misspelled the module name or forgot to load it\\.')); expect(element.html()).toBe('{{1+2}}'); dealoc(element); diff --git a/test/auto/injectorSpec.js b/test/auto/injectorSpec.js index 22686b98b0c3..eecde9bf33b4 100644 --- a/test/auto/injectorSpec.js +++ b/test/auto/injectorSpec.js @@ -110,6 +110,7 @@ describe('injector', function() { function fn(a, b, c, d) { + /* jshint -W040 */ args = [this, a, b, c, d]; return a + b + c + d; } @@ -147,6 +148,7 @@ describe('injector', function() { describe('annotation', function() { + /* global annotate: false */ it('should return $inject', function() { function fn() {} fn.$inject = ['a']; @@ -159,6 +161,7 @@ describe('injector', function() { it('should create $inject', function() { + var extraParans = angular.noop; // keep the multi-line to make sure we can handle it function $f_n0 /* */( @@ -175,7 +178,7 @@ describe('injector', function() { it('should strip leading and trailing underscores from arg name during inference', function() { - function beforeEachFn(_foo_) { /* foo = _foo_ */ }; + function beforeEachFn(_foo_) { /* foo = _foo_ */ } expect(annotate(beforeEachFn)).toEqual(['foo']); }); @@ -240,9 +243,9 @@ describe('injector', function() { describe('module', function() { it('should provide $injector even when no module is requested', function() { var $provide, - $injector = createInjector([ - angular.extend(function(p) { $provide = p; }, {$inject: ['$provide']}) - ]); + $injector = createInjector([ + angular.extend(function(p) { $provide = p; }, {$inject: ['$provide']}) + ]); expect($injector.get('$injector')).toBe($injector); }); @@ -298,9 +301,9 @@ describe('injector', function() { angular.module('a', [], function(){ log += 'a'; }).run(function() { log += 'A'; }); angular.module('b', ['a'], function(){ log += 'b'; }).run(function() { log += 'B'; }); createInjector([ - 'b', - valueFn(function() { log += 'C'; }), - [valueFn(function() { log += 'D'; })] + 'b', + valueFn(function() { log += 'C'; }), + [valueFn(function() { log += 'D'; })] ]); expect(log).toEqual('abABCD'); }); @@ -328,19 +331,19 @@ describe('injector', function() { it('should create configuration injectable constants', function() { var log = []; createInjector([ - function($provide){ - $provide.constant('abc', 123); - $provide.constant({a: 'A', b:'B'}); - return function(a) { - log.push(a); - } - }, - function(abc) { - log.push(abc); - return function(b) { - log.push(b); - } - } + function($provide){ + $provide.constant('abc', 123); + $provide.constant({a: 'A', b:'B'}); + return function(a) { + log.push(a); + }; + }, + function(abc) { + log.push(abc); + return function(b) { + log.push(b); + }; + } ]).get('abc'); expect(log).toEqual([123, 'A', 'B']); }); @@ -422,7 +425,7 @@ describe('injector', function() { it('should configure $provide provider type', function() { - function Type() {}; + function Type() {} Type.prototype.$get = function() { expect(this instanceof Type).toBe(true); return 'abc'; @@ -436,7 +439,7 @@ describe('injector', function() { it('should configure $provide using an array', function() { function Type(PREFIX) { this.prefix = PREFIX; - }; + } Type.prototype.$get = function() { return this.prefix + 'def'; }; @@ -527,7 +530,7 @@ describe('injector', function() { return function(val) { log.push('myService:' + val + ',' + dep1); return 'origReturn'; - } + }; }]); $provide.decorator('myService', function($delegate) { @@ -554,7 +557,7 @@ describe('injector', function() { return function(val) { log.push('myService:' + val); return 'origReturn'; - } + }; }); $provide.decorator('myService', function($delegate, dep1) { @@ -704,7 +707,8 @@ describe('injector', function() { })).toEqual('melville:moby'); expect($injector.invoke(function(book, author) { expect(this).toEqual($injector); - return author + ':' + book;}, $injector)).toEqual('melville:moby'); + return author + ':' + book; + }, $injector)).toEqual('melville:moby'); }); @@ -722,7 +726,7 @@ describe('injector', function() { it('should invoke method which is annotated', function() { expect($injector.invoke(extend(function(b, a) { - return a + ':' + b + return a + ':' + b; }, {$inject:['book', 'author']}))).toEqual('melville:moby'); expect($injector.invoke(extend(function(b, a) { expect(this).toEqual($injector); @@ -855,10 +859,10 @@ describe('injector', function() { it('should prevent instance lookup in module', function() { - function instanceLookupInModule(name) { throw Error('FAIL'); } + function instanceLookupInModule(name) { throw new Error('FAIL'); } expect(function() { createInjector([function($provide) { - $provide.value('name', 'angular') + $provide.value('name', 'angular'); }, instanceLookupInModule]); }).toThrowMatching(/\[\$injector:unpr] Unknown provider: name/); }); @@ -920,7 +924,7 @@ describe('strict-di injector', function() { it('should throw if magic annotation is used by factory', function() { module(function($provide) { $provide.factory({ - '$test': function($rootScope) { return function() {} }, + '$test': function($rootScope) { return function() {}; }, }); }); inject(function($injector) { diff --git a/test/e2e/docsAppE2E.js b/test/e2e/docsAppE2E.js index 8fe30c38b219..b3fe257ee340 100644 --- a/test/e2e/docsAppE2E.js +++ b/test/e2e/docsAppE2E.js @@ -1,3 +1,5 @@ +'use strict'; + describe('docs.angularjs.org', function () { describe('App', function () { // it('should filter the module list when searching', function () { @@ -66,4 +68,4 @@ describe('docs.angularjs.org', function () { expect(element(by.css('.minerr-errmsg')).getText()).toEqual("Argument 'Missing' is not a function, got undefined"); }); }); -}); \ No newline at end of file +}); diff --git a/test/helpers/matchers.js b/test/helpers/matchers.js index c5d7d6cfd3c6..b18604bf9ba4 100644 --- a/test/helpers/matchers.js +++ b/test/helpers/matchers.js @@ -1,3 +1,5 @@ +'use strict'; + beforeEach(function() { function cssMatcher(presentClasses, absentClasses) { @@ -39,7 +41,7 @@ beforeEach(function() { } }); return hidden; - }; + } this.addMatchers({ toBeInvalid: cssMatcher('ng-invalid', 'ng-valid'), @@ -128,7 +130,7 @@ beforeEach(function() { this.message = function() { if (this.actual.callCount != 1) { - if (this.actual.callCount == 0) { + if (this.actual.callCount === 0) { return [ 'Expected spy ' + this.actual.identity + ' to have been called once with ' + jasmine.pp(expectedArgs) + ' but it was never called.', diff --git a/test/helpers/privateMocks.js b/test/helpers/privateMocks.js index 6d9fb34fc474..0e54f8e9d769 100644 --- a/test/helpers/privateMocks.js +++ b/test/helpers/privateMocks.js @@ -1,3 +1,5 @@ +'use strict'; + function createMockStyleSheet(doc, wind) { doc = doc ? doc[0] : document; wind = wind || window; @@ -17,7 +19,7 @@ function createMockStyleSheet(doc, wind) { try { ss.addRule(selector, styles); } - catch(e) {} + catch(e2) {} } }, @@ -25,4 +27,4 @@ function createMockStyleSheet(doc, wind) { head.removeChild(node); } }; -}; +} diff --git a/test/helpers/privateMocksSpec.js b/test/helpers/privateMocksSpec.js index d5a1e188ea57..6d86ecb81c2a 100644 --- a/test/helpers/privateMocksSpec.js +++ b/test/helpers/privateMocksSpec.js @@ -1,3 +1,5 @@ +'use strict'; + describe('private mocks', function() { describe('createMockStyleSheet', function() { @@ -29,7 +31,7 @@ describe('private mocks', function() { return node.currentStyle ? node.currentStyle[key] : $window.getComputedStyle(node)[key]; - }; + } })); }); diff --git a/test/helpers/testabilityPatch.js b/test/helpers/testabilityPatch.js index 34b6b78a0141..658d1883c102 100644 --- a/test/helpers/testabilityPatch.js +++ b/test/helpers/testabilityPatch.js @@ -1,3 +1,4 @@ +/* global jQuery: true, uid: true */ 'use strict'; /** @@ -150,7 +151,7 @@ function sortedHtml(element, showNgClass) { var attr = attributes[i]; if(attr.name.match(/^ng[\:\-]/) || - (attr.value || attr.value == '') && + (attr.value || attr.value === '') && attr.value !='null' && attr.value !='auto' && attr.value !='false' && @@ -283,7 +284,7 @@ function provideLog($provide) { var currentMessages = messages; messages = []; return currentMessages; - } + }; log.fn = function(msg) { return function() { @@ -299,7 +300,7 @@ function provideLog($provide) { function pending() { dump('PENDING'); -}; +} function trace(name) { dump(new Error(name).stack); diff --git a/test/jQueryPatchSpec.js b/test/jQueryPatchSpec.js index c42bbb708c20..10e46be8a499 100644 --- a/test/jQueryPatchSpec.js +++ b/test/jQueryPatchSpec.js @@ -1,3 +1,4 @@ +/* global $: false */ 'use strict'; if (window.jQuery) { diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js index f9c6f3a2b55f..8bab591ae173 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -1,3 +1,5 @@ +'use strict'; + describe('jqLite', function() { var scope, a, b, c; @@ -57,7 +59,7 @@ describe('jqLite', function() { it('should allow construction with html', function() { var nodes = jqLite('
1
2'); expect(nodes[0].parentNode).toBeDefined(); - expect(nodes[0].parentNode.nodeType).toBe(11); /** Document Fragment **/; + expect(nodes[0].parentNode.nodeType).toBe(11); /** Document Fragment **/ expect(nodes[0].parentNode).toBe(nodes[1].parentNode); expect(nodes.length).toEqual(2); expect(nodes[0].innerHTML).toEqual('1'); @@ -68,7 +70,7 @@ describe('jqLite', function() { it('should allow construction of html with leading whitespace', function() { var nodes = jqLite(' \n\r \r\n
1
2'); expect(nodes[0].parentNode).toBeDefined(); - expect(nodes[0].parentNode.nodeType).toBe(11); /** Document Fragment **/; + expect(nodes[0].parentNode.nodeType).toBe(11); /** Document Fragment **/ expect(nodes[0].parentNode).toBe(nodes[1].parentNode); expect(nodes.length).toBe(2); expect(nodes[0].innerHTML).toBe('1'); @@ -473,7 +475,7 @@ describe('jqLite', function() { span = div.find('span'), log = ''; - span.on('click', function() { log+= 'click;'}); + span.on('click', function() { log += 'click;'; }); browserTrigger(span); expect(log).toEqual('click;'); @@ -945,21 +947,21 @@ describe('jqLite', function() { if (jqLite.fn) return; // don't run in jQuery var eventFn; var window = { - document: {}, - location: {}, - alert: noop, - setInterval: noop, - length:10, // pretend you are an array - addEventListener: function(type, fn){ - expect(type).toEqual('hashchange'); - eventFn = fn; - }, - removeEventListener: noop, - attachEvent: function(type, fn){ - expect(type).toEqual('onhashchange'); - eventFn = fn; - }, - detachEvent: noop + document: {}, + location: {}, + alert: noop, + setInterval: noop, + length:10, // pretend you are an array + addEventListener: function(type, fn){ + expect(type).toEqual('hashchange'); + eventFn = fn; + }, + removeEventListener: noop, + attachEvent: function(type, fn){ + expect(type).toEqual('onhashchange'); + eventFn = fn; + }, + detachEvent: noop }; var log; var jWindow = jqLite(window).on('hashchange', function() { @@ -1046,16 +1048,17 @@ describe('jqLite', function() { if (window.jQuery) return; var browserMoveTrigger = function(from, to){ var fireEvent = function(type, element, relatedTarget){ - var msie = parseInt((/msie (\d+)/.exec(navigator.userAgent.toLowerCase()) || [])[1]); + var evnt, msie = parseInt((/msie (\d+)/.exec(navigator.userAgent.toLowerCase()) || [])[1]); if (msie < 9){ - var evnt = document.createEventObject(); + evnt = document.createEventObject(); evnt.srcElement = element; evnt.relatedTarget = relatedTarget; element.fireEvent('on' + type, evnt); return; - }; - var evnt = document.createEvent('MouseEvents'), - originalPreventDefault = evnt.preventDefault, + } + evnt = document.createEvent('MouseEvents'); + + var originalPreventDefault = evnt.preventDefault, appWindow = window, fakeProcessDefault = true, finalProcessDefault; @@ -1656,26 +1659,25 @@ describe('jqLite', function() { describe('camelCase', function() { - - it('should leave non-dashed strings alone', function() { - expect(camelCase('foo')).toBe('foo'); - expect(camelCase('')).toBe(''); - expect(camelCase('fooBar')).toBe('fooBar'); - }); + it('should leave non-dashed strings alone', function() { + expect(camelCase('foo')).toBe('foo'); + expect(camelCase('')).toBe(''); + expect(camelCase('fooBar')).toBe('fooBar'); + }); - it('should covert dash-separated strings to camelCase', function() { - expect(camelCase('foo-bar')).toBe('fooBar'); - expect(camelCase('foo-bar-baz')).toBe('fooBarBaz'); - expect(camelCase('foo:bar_baz')).toBe('fooBarBaz'); - }); + it('should covert dash-separated strings to camelCase', function() { + expect(camelCase('foo-bar')).toBe('fooBar'); + expect(camelCase('foo-bar-baz')).toBe('fooBarBaz'); + expect(camelCase('foo:bar_baz')).toBe('fooBarBaz'); + }); - it('should covert browser specific css properties', function() { - expect(camelCase('-moz-foo-bar')).toBe('MozFooBar'); - expect(camelCase('-webkit-foo-bar')).toBe('webkitFooBar'); - expect(camelCase('-webkit-foo-bar')).toBe('webkitFooBar'); - }); + it('should covert browser specific css properties', function() { + expect(camelCase('-moz-foo-bar')).toBe('MozFooBar'); + expect(camelCase('-webkit-foo-bar')).toBe('webkitFooBar'); + expect(camelCase('-webkit-foo-bar')).toBe('webkitFooBar'); + }); }); }); diff --git a/test/jquery_alias.js b/test/jquery_alias.js index ee4094f24b85..d43920d7431b 100644 --- a/test/jquery_alias.js +++ b/test/jquery_alias.js @@ -1,3 +1,4 @@ +/* global _jQuery: true, _jqLiteMode: true */ 'use strict'; var _jQuery = jQuery, diff --git a/test/jquery_remove.js b/test/jquery_remove.js index 66029c81f50a..c1b41a09fd0c 100644 --- a/test/jquery_remove.js +++ b/test/jquery_remove.js @@ -1,3 +1,4 @@ +/* global _jQuery: true, _jqLiteMode: true */ 'use strict'; var _jQuery = jQuery.noConflict(true), diff --git a/test/loaderSpec.js b/test/loaderSpec.js index 816e0a10603c..e17f329f32e5 100644 --- a/test/loaderSpec.js +++ b/test/loaderSpec.js @@ -81,5 +81,5 @@ describe('module loader', function() { it('should expose `$$minErr` on the `angular` object', function() { expect(window.angular.$$minErr).toEqual(jasmine.any(Function)); - }) + }); }); diff --git a/test/ng/anchorScrollSpec.js b/test/ng/anchorScrollSpec.js index ba64d1a5363c..e7933d630195 100644 --- a/test/ng/anchorScrollSpec.js +++ b/test/ng/anchorScrollSpec.js @@ -1,3 +1,4 @@ +'use strict'; describe('$anchorScroll', function() { var elmSpy; diff --git a/test/ng/animateSpec.js b/test/ng/animateSpec.js index b9dd1493330e..30e4273b12cf 100644 --- a/test/ng/animateSpec.js +++ b/test/ng/animateSpec.js @@ -1,6 +1,10 @@ +'use strict'; + describe("$animate", function() { describe("without animation", function() { + var element, $rootElement; + beforeEach(module(function() { return function($compile, _$rootElement_, $rootScope) { element = $compile('
')($rootScope); diff --git a/test/ng/browserSpecs.js b/test/ng/browserSpecs.js index 4157ecbdb7fd..dae55594cda4 100755 --- a/test/ng/browserSpecs.js +++ b/test/ng/browserSpecs.js @@ -18,7 +18,7 @@ function MockWindow() { }; this.addEventListener = function(name, listener) { - if (isUndefined(events[name])) events[name] = []; + if (angular.isUndefined(events[name])) events[name] = []; events[name].push(listener); }; @@ -49,7 +49,7 @@ function MockWindow() { function MockDocument() { var self = this; - this[0] = window.document + this[0] = window.document; this.basePath = '/'; this.find = function(name) { @@ -62,15 +62,15 @@ function MockDocument() { throw new Error(name); } } - } + }; } else { throw new Error(name); } - } + }; } describe('browser', function() { - + /* global Browser: false */ var browser, fakeWindow, fakeDocument, logs, scripts, removedScripts, sniffer; beforeEach(function() { diff --git a/test/ng/cacheFactorySpec.js b/test/ng/cacheFactorySpec.js index b1a018dab879..c0d3c4808d9c 100644 --- a/test/ng/cacheFactorySpec.js +++ b/test/ng/cacheFactorySpec.js @@ -1,3 +1,5 @@ +'use strict'; + describe('$cacheFactory', function() { it('should be injected', inject(function($cacheFactory) { @@ -176,7 +178,7 @@ describe('$cacheFactory', function() { describe('LRU cache', function() { it('should create cache with defined capacity', inject(function($cacheFactory) { - cache = $cacheFactory('cache1', {capacity: 5}); + var cache = $cacheFactory('cache1', {capacity: 5}); expect(cache.info().size).toBe(0); for (var i=0; i<5; i++) { @@ -193,6 +195,7 @@ describe('$cacheFactory', function() { describe('eviction', function() { + var cache; beforeEach(inject(function($cacheFactory) { cache = $cacheFactory('cache1', {capacity: 2}); diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 4e6d85c7dc1d..41bf4854b46d 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -82,13 +82,13 @@ describe('$compile', function() { element.text('SUCCESS'); } }; - }) + }); }); inject(function($compile, $rootScope, log) { element = $compile('
')($rootScope); expect(element.text()).toEqual('SUCCESS'); expect(log).toEqual('OK'); - }) + }); }); it('should allow registration of multiple directives with same name', function() { @@ -282,7 +282,7 @@ describe('$compile', function() { expect(attr).toBe(templateAttr); expect(scope).toEqual($rootScope); element.text('worked'); - } + }; } }; }); @@ -331,8 +331,7 @@ describe('$compile', function() { parts.sort(); parts.unshift(elementName); forEach(parts, function(value, key){ - if (value.substring(0,3) == 'ng-') { - } else { + if (value.substring(0,3) !== 'ng-') { value = value.replace('=""', ''); var match = value.match(/=(.*)/); if (match && match[1].charAt(0) != '"') { @@ -398,7 +397,7 @@ describe('$compile', function() { expect(element.children().length).toBe(1); expect(element.text()).toBe('Hello'); }); - }) + }); }); describe('compiler control', function() { @@ -437,46 +436,46 @@ describe('$compile', function() { describe('restrict', function() { it('should allow restriction of attributes', function() { - module(function() { - forEach({div:'E', attr:'A', clazz:'C', all:'EAC'}, function(restrict, name) { - directive(name, function(log) { - return { - restrict: restrict, - compile: valueFn(function(scope, element, attr) { - log(name); - }) - }; - }); + module(function() { + forEach({div:'E', attr:'A', clazz:'C', all:'EAC'}, function(restrict, name) { + directive(name, function(log) { + return { + restrict: restrict, + compile: valueFn(function(scope, element, attr) { + log(name); + }) + }; }); }); - inject(function($rootScope, $compile, log) { - dealoc($compile('')($rootScope)); - expect(log).toEqual(''); - log.reset(); + }); + inject(function($rootScope, $compile, log) { + dealoc($compile('')($rootScope)); + expect(log).toEqual(''); + log.reset(); - dealoc($compile('
')($rootScope)); - expect(log).toEqual('div'); - log.reset(); + dealoc($compile('
')($rootScope)); + expect(log).toEqual('div'); + log.reset(); - dealoc($compile('')($rootScope)); - expect(log).toEqual(''); - log.reset(); + dealoc($compile('')($rootScope)); + expect(log).toEqual(''); + log.reset(); - dealoc($compile('')($rootScope)); - expect(log).toEqual('attr'); - log.reset(); + dealoc($compile('')($rootScope)); + expect(log).toEqual('attr'); + log.reset(); - dealoc($compile('')($rootScope)); - expect(log).toEqual(''); - log.reset(); + dealoc($compile('')($rootScope)); + expect(log).toEqual(''); + log.reset(); - dealoc($compile('')($rootScope)); - expect(log).toEqual('clazz'); - log.reset(); + dealoc($compile('')($rootScope)); + expect(log).toEqual('clazz'); + log.reset(); - dealoc($compile('')($rootScope)); - expect(log).toEqual('all; all; all'); - }); + dealoc($compile('')($rootScope)); + expect(log).toEqual('all; all; all'); + }); }); }); @@ -640,7 +639,8 @@ describe('$compile', function() { element = $compile('
')($rootScope); $rootScope.$digest(); expect(element.css('width')).toBe('2px'); - })); + } + )); } it('should merge interpolated css class', inject(function($compile, $rootScope) { @@ -681,19 +681,19 @@ describe('$compile', function() { return { replace: true, template: 'dada' - } + }; }); directive('multiRootElem', function() { return { replace: true, template: '
' - } + }; }); directive('singleRootWithWhiteSpace', function() { return { replace: true, template: '
\n' - } + }; }); }); @@ -802,32 +802,38 @@ describe('$compile', function() { beforeEach(module( function() { directive('hello', valueFn({ - restrict: 'CAM', templateUrl: 'hello.html', transclude: true + restrict: 'CAM', + templateUrl: 'hello.html', + transclude: true })); directive('cau', valueFn({ - restrict: 'CAM', templateUrl: 'cau.html' + restrict: 'CAM', + templateUrl: 'cau.html' })); directive('crossDomainTemplate', valueFn({ - restrict: 'CAM', templateUrl: 'http://example.com/should-not-load.html' - })); - directive('trustedTemplate', function($sce) { return { restrict: 'CAM', - templateUrl: function() { - return $sce.trustAsResourceUrl('http://example.com/trusted-template.html'); - }}; + templateUrl: 'http://example.com/should-not-load.html' + })); + directive('trustedTemplate', function($sce) { + return { + restrict: 'CAM', + templateUrl: function() { + return $sce.trustAsResourceUrl('http://example.com/trusted-template.html'); + } + }; }); directive('cError', valueFn({ restrict: 'CAM', templateUrl:'error.html', compile: function() { - throw Error('cError'); + throw new Error('cError'); } })); directive('lError', valueFn({ restrict: 'CAM', templateUrl: 'error.html', compile: function() { - throw Error('lError'); + throw new Error('lError'); } })); @@ -848,7 +854,7 @@ describe('$compile', function() { replace: true, templateUrl:'error.html', compile: function() { - throw Error('cError'); + throw new Error('cError'); } })); directive('iLError', valueFn({ @@ -856,7 +862,7 @@ describe('$compile', function() { replace: true, templateUrl: 'error.html', compile: function() { - throw Error('lError'); + throw new Error('lError'); } })); @@ -901,23 +907,25 @@ describe('$compile', function() { )); it('should not load cross domain templates by default', inject( - function($compile, $rootScope, $templateCache, $sce) { - expect(function() { - $templateCache.put('http://example.com/should-not-load.html', 'Should not load even if in cache.'); - $compile('
')($rootScope); - }).toThrowMinErr('$sce', 'insecurl', 'Blocked loading resource from url not allowed by $sceDelegate policy. URL: http://example.com/should-not-load.html'); - })); + function($compile, $rootScope, $templateCache, $sce) { + expect(function() { + $templateCache.put('http://example.com/should-not-load.html', 'Should not load even if in cache.'); + $compile('
')($rootScope); + }).toThrowMinErr('$sce', 'insecurl', 'Blocked loading resource from url not allowed by $sceDelegate policy. URL: http://example.com/should-not-load.html'); + } + )); it('should load cross domain templates when trusted', inject( - function($compile, $httpBackend, $rootScope, $sce) { - $httpBackend.expect('GET', 'http://example.com/trusted-template.html').respond('example.com/trusted_template_contents'); - element = $compile('
')($rootScope); - expect(sortedHtml(element)). - toEqual('
'); - $httpBackend.flush(); - expect(sortedHtml(element)). - toEqual('
example.com/trusted_template_contents
'); - })); + function($compile, $httpBackend, $rootScope, $sce) { + $httpBackend.expect('GET', 'http://example.com/trusted-template.html').respond('example.com/trusted_template_contents'); + element = $compile('
')($rootScope); + expect(sortedHtml(element)). + toEqual('
'); + $httpBackend.flush(); + expect(sortedHtml(element)). + toEqual('
example.com/trusted_template_contents
'); + } + )); it('should append template via $http and cache it in $templateCache', inject( function($compile, $httpBackend, $templateCache, $rootScope, $browser) { @@ -1275,15 +1283,15 @@ describe('$compile', function() { function logDirective (name, priority, options) { directive(name, function(log) { return (extend({ - priority: priority, - compile: function() { - log(name + '-C'); - return { - pre: function() { log(name + '-PreL'); }, - post: function() { log(name + '-PostL'); } - } - } - }, options || {})); + priority: priority, + compile: function() { + log(name + '-C'); + return { + pre: function() { log(name + '-PreL'); }, + post: function() { log(name + '-PostL'); } + }; + } + }, options || {})); }); } @@ -1444,7 +1452,7 @@ describe('$compile', function() { return { replace: true, templateUrl: 'template.html' - } + }; }); }); @@ -2006,9 +2014,9 @@ describe('$compile', function() { post: function($scope, $element, $attrs) { log('postLink=' + $attrs.myName); } - } + }; } - } + }; }); }); module(function() { @@ -2022,7 +2030,7 @@ describe('$compile', function() { } }; } - } + }; }); }); inject(function($rootScope, $compile, log) { @@ -2133,7 +2141,7 @@ describe('$compile', function() { it('should translate {{}} in terminal nodes', inject(function($rootScope, $compile) { - element = $compile('')($rootScope) + element = $compile('')($rootScope); $rootScope.$digest(); expect(sortedHtml(element).replace(' selected="true"', '')). toEqual('')($rootScope) + element = $compile('')($rootScope); $rootScope.isChecked = false; $rootScope.$digest(); expect(element.attr('checked')).toBeFalsy(); @@ -43,8 +43,8 @@ describe('boolean attr directives', function() { it('should bind selected', inject(function($rootScope, $compile) { - element = $compile('')($rootScope) - jqLite(document.body).append(element) + element = $compile('')($rootScope); + jqLite(document.body).append(element); $rootScope.isSelected=false; $rootScope.$digest(); expect(element.children()[1].selected).toBeFalsy(); @@ -55,7 +55,7 @@ describe('boolean attr directives', function() { it('should bind readonly', inject(function($rootScope, $compile) { - element = $compile('')($rootScope) + element = $compile('')($rootScope); $rootScope.isReadonly=false; $rootScope.$digest(); expect(element.attr('readOnly')).toBeFalsy(); @@ -66,7 +66,7 @@ describe('boolean attr directives', function() { it('should bind open', inject(function($rootScope, $compile) { - element = $compile('
')($rootScope) + element = $compile('
')($rootScope); $rootScope.isOpen=false; $rootScope.$digest(); expect(element.attr('open')).toBeFalsy(); @@ -78,7 +78,7 @@ describe('boolean attr directives', function() { describe('multiple', function() { it('should NOT bind to multiple via ngMultiple', inject(function($rootScope, $compile) { - element = $compile('')($rootScope) + element = $compile('')($rootScope); $rootScope.isMultiple=false; $rootScope.$digest(); expect(element.attr('multiple')).toBeFalsy(); @@ -92,7 +92,7 @@ describe('boolean attr directives', function() { if (msie < 9) return; //IE8 doesn't support biding to boolean attributes expect(function() { - $compile('') + $compile(''); }).toThrowMinErr('$compile', 'selmulti', 'Binding to the \'multiple\' attribute is not supported. ' + 'Element: '+ ''+ ''); - expect(function() { - $compile(doc)(scope); - }).toThrowMinErr('ng', 'badname'); + expect(function() { + $compile(doc)(scope); + }).toThrowMinErr('ng', 'badname'); }); @@ -177,7 +178,7 @@ describe('form', function() { scope.submitMe = function() { submitted = true; - } + }; if (msie!=8) addEventListenerFn(doc[0], 'submit', assertPreventDefaultListener); @@ -218,11 +219,11 @@ describe('form', function() { // $location change) that will cause some directive to destroy the dom (e.g. ngView+$route) doc.empty(); destroyed = true; - } + }; scope.submitMe = function() { submitted = true; - } + }; var assertPreventDefaultListener = function(e) { reloadPrevented = e.defaultPrevented || (e.returnValue === false); @@ -434,7 +435,7 @@ describe('form', function() { expect(parent.$error.myRule).toBe(false); expect(child.$error.myRule).toBe(false); }); - }) + }); describe('validation', function() { diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js index e9b28f1e7464..a87d3cc51261 100644 --- a/test/ng/directive/inputSpec.js +++ b/test/ng/directive/inputSpec.js @@ -1,6 +1,7 @@ 'use strict'; describe('NgModelController', function() { + /* global NgModelController: false */ var ctrl, scope, ngModelAccessor, element, parentFormCtrl; beforeEach(inject(function($rootScope, $controller) { @@ -9,7 +10,7 @@ describe('NgModelController', function() { parentFormCtrl = { $setValidity: jasmine.createSpy('$setValidity'), $setDirty: jasmine.createSpy('$setDirty') - } + }; element = jqLite('
'); element.data('$formController', parentFormCtrl); @@ -17,7 +18,9 @@ describe('NgModelController', function() { scope = $rootScope; ngModelAccessor = jasmine.createSpy('ngModel accessor'); ctrl = $controller(NgModelController, { - $scope: scope, $element: element.find('input'), $attrs: attrs + $scope: scope, + $element: element.find('input'), + $attrs: attrs }); })); @@ -387,24 +390,24 @@ describe('ngModel', function() { it('should keep previously defined watches consistent when changes in validity are made', inject(function($compile, $rootScope) { - var isFormValid; - $rootScope.$watch('myForm.$valid', function(value) { isFormValid = value; }); + var isFormValid; + $rootScope.$watch('myForm.$valid', function(value) { isFormValid = value; }); - var element = $compile('
' + + var element = $compile('' + '' + '
')($rootScope); - $rootScope.$apply(); - expect(isFormValid).toBe(false); - expect($rootScope.myForm.$valid).toBe(false); + $rootScope.$apply(); + expect(isFormValid).toBe(false); + expect($rootScope.myForm.$valid).toBe(false); - $rootScope.value='value'; - $rootScope.$apply(); - expect(isFormValid).toBe(true); - expect($rootScope.myForm.$valid).toBe(true); + $rootScope.value='value'; + $rootScope.$apply(); + expect(isFormValid).toBe(true); + expect($rootScope.myForm.$valid).toBe(true); - dealoc(element); - })); + dealoc(element); + })); }); @@ -454,7 +457,7 @@ describe('input', function() { this.message = function() { return "Attribute '" + attributeName + "' expected to be off but was '" + actualValue + "' in: " + angular.mock.dump(this.actual); - } + }; return !actualValue || actualValue == 'false'; } @@ -477,7 +480,7 @@ describe('input', function() { expect(scope.name).toEqual('adam'); }); - if (!(msie < 9)) { + if (!msie || msie >= 9) { describe('compositionevents', function() { it('should not update the model between "compositionstart" and "compositionend" on non android', inject(function($sniffer) { $sniffer.android = false; @@ -511,7 +514,7 @@ describe('input', function() { it('should update the model on "compositionend"', function() { compileInput(''); - if (!(msie < 9)) { + if (!msie || msie >= 9) { browserTrigger(inputElm, 'compositionstart'); changeInputValueTo('caitp'); expect(scope.name).toBeUndefined(); @@ -1063,409 +1066,409 @@ describe('input', function() { // INPUT TYPES describe('month', function (){ - it('should render blank if model is not a Date object', function() { - compileInput(''); + it('should render blank if model is not a Date object', function() { + compileInput(''); + + scope.$apply(function(){ + scope.january = '2013-01'; + }); + + expect(inputElm.val()).toBe(''); + }); - scope.$apply(function(){ - scope.january = '2013-01'; - }); + it('should set the view if the model is a valid Date object', function (){ + compileInput(''); - expect(inputElm.val()).toBe(''); + scope.$apply(function(){ + scope.march = new Date(2013, 2, 1); }); - it('should set the view if the model is a valid Date object', function (){ - compileInput(''); + expect(inputElm.val()).toBe('2013-03'); + }); - scope.$apply(function(){ - scope.march = new Date(2013, 2, 1); - }); + it('should set the model undefined if the input is an invalid month string', function () { + compileInput(''); - expect(inputElm.val()).toBe('2013-03'); + scope.$apply(function(){ + scope.value = new Date(2013, 0, 1); }); - it('should set the model undefined if the input is an invalid month string', function () { - compileInput(''); - scope.$apply(function(){ - scope.value = new Date(2013, 0, 1); - }); + expect(inputElm.val()).toBe('2013-01'); + try { + //set to text for browsers with datetime-local validation. + inputElm[0].setAttribute('type', 'text'); + } catch(e) { + //for IE8 + } - expect(inputElm.val()).toBe('2013-01'); + changeInputValueTo('stuff'); + expect(inputElm.val()).toBe('stuff'); + expect(scope.value).toBeUndefined(); + expect(inputElm).toBeInvalid(); + }); - try { - //set to text for browsers with datetime-local validation. - inputElm[0].setAttribute('type', 'text'); - } catch(e) { - //for IE8 - } + it('should render as blank if null', function() { + compileInput(''); - changeInputValueTo('stuff'); - expect(inputElm.val()).toBe('stuff'); - expect(scope.value).toBeUndefined(); - expect(inputElm).toBeInvalid(); + scope.$apply(function() { + scope.test = null; }); - it('should render as blank if null', function() { - compileInput(''); + expect(scope.test).toBeNull(); + expect(inputElm.val()).toEqual(''); + }); + + it('should come up blank when no value specified', function() { + compileInput(''); - scope.$apply(function() { - scope.test = null; - }); + scope.$digest(); + expect(inputElm.val()).toBe(''); - expect(scope.test).toBeNull(); - expect(inputElm.val()).toEqual(''); + scope.$apply(function() { + scope.test = null; }); - it('should come up blank when no value specified', function() { - compileInput(''); + expect(scope.test).toBeNull(); + expect(inputElm.val()).toBe(''); + }); - scope.$digest(); - expect(inputElm.val()).toBe(''); - scope.$apply(function() { - scope.test = null; - }); + it('should parse empty string to null', function() { + compileInput(''); - expect(scope.test).toBeNull(); - expect(inputElm.val()).toBe(''); + scope.$apply(function() { + scope.test = new Date(2011, 0, 1); }); + changeInputValueTo(''); + expect(scope.test).toBeNull(); + expect(inputElm).toBeValid(); + }); - it('should parse empty string to null', function() { - compileInput(''); - scope.$apply(function() { - scope.test = new Date(2011, 0, 1); - }); + describe('min', function (){ + beforeEach(function (){ + compileInput(''); + scope.$digest(); + }); - changeInputValueTo(''); - expect(scope.test).toBeNull(); - expect(inputElm).toBeValid(); + it('should invalidate', function (){ + changeInputValueTo('2012-12'); + expect(inputElm).toBeInvalid(); + expect(scope.value).toBeFalsy(); + expect(scope.form.alias.$error.min).toBeTruthy(); + }); + + it('should validate', function (){ + changeInputValueTo('2013-07'); + expect(inputElm).toBeValid(); + expect(+scope.value).toBe(+new Date(2013, 6, 1)); + expect(scope.form.alias.$error.min).toBeFalsy(); + }); + }); + + describe('max', function(){ + beforeEach(function (){ + compileInput(''); + scope.$digest(); }); + it('should validate', function (){ + changeInputValueTo('2012-03'); + expect(inputElm).toBeValid(); + expect(+scope.value).toBe(+new Date(2012, 2, 1)); + expect(scope.form.alias.$error.max).toBeFalsy(); + }); - describe('min', function (){ - beforeEach(function (){ - compileInput(''); - scope.$digest(); - }); - - it('should invalidate', function (){ - changeInputValueTo('2012-12'); - expect(inputElm).toBeInvalid(); - expect(scope.value).toBeFalsy(); - expect(scope.form.alias.$error.min).toBeTruthy(); - }); - - it('should validate', function (){ - changeInputValueTo('2013-07'); - expect(inputElm).toBeValid(); - expect(+scope.value).toBe(+new Date(2013, 6, 1)); - expect(scope.form.alias.$error.min).toBeFalsy(); - }); - }); - - describe('max', function(){ - beforeEach(function (){ - compileInput(''); - scope.$digest(); - }); - - it('should validate', function (){ - changeInputValueTo('2012-03'); - expect(inputElm).toBeValid(); - expect(+scope.value).toBe(+new Date(2012, 2, 1)); - expect(scope.form.alias.$error.max).toBeFalsy(); - }); - - it('should invalidate', function (){ - changeInputValueTo('2013-05'); - expect(inputElm).toBeInvalid(); - expect(scope.value).toBeUndefined(); - expect(scope.form.alias.$error.max).toBeTruthy(); - }); + it('should invalidate', function (){ + changeInputValueTo('2013-05'); + expect(inputElm).toBeInvalid(); + expect(scope.value).toBeUndefined(); + expect(scope.form.alias.$error.max).toBeTruthy(); }); + }); }); - describe('week', function (){ - it('should set render blank if model is not a Date object', function() { - compileInput(''); + describe('week', function (){ + it('should set render blank if model is not a Date object', function() { + compileInput(''); + + scope.$apply(function(){ + scope.secondWeek = '2013-W02'; + }); + + expect(inputElm.val()).toBe(''); + }); - scope.$apply(function(){ - scope.secondWeek = '2013-W02'; - }); + it('should set the view if the model is a valid Date object', function (){ + compileInput(''); - expect(inputElm.val()).toBe(''); + scope.$apply(function(){ + scope.secondWeek = new Date(2013, 0, 11); }); - it('should set the view if the model is a valid Date object', function (){ - compileInput(''); + expect(inputElm.val()).toBe('2013-W02'); + }); - scope.$apply(function(){ - scope.secondWeek = new Date(2013, 0, 11); - }); + it('should set the model undefined if the input is an invalid week string', function () { + compileInput(''); - expect(inputElm.val()).toBe('2013-W02'); + scope.$apply(function(){ + scope.value = new Date(2013, 0, 11); }); - it('should set the model undefined if the input is an invalid week string', function () { - compileInput(''); - scope.$apply(function(){ - scope.value = new Date(2013, 0, 11); - }); + expect(inputElm.val()).toBe('2013-W02'); + try { + //set to text for browsers with datetime-local validation. + inputElm[0].setAttribute('type', 'text'); + } catch(e) { + //for IE8 + } - expect(inputElm.val()).toBe('2013-W02'); + changeInputValueTo('stuff'); + expect(inputElm.val()).toBe('stuff'); + expect(scope.value).toBeUndefined(); + expect(inputElm).toBeInvalid(); + }); - try { - //set to text for browsers with datetime-local validation. - inputElm[0].setAttribute('type', 'text'); - } catch(e) { - //for IE8 - } + it('should render as blank if null', function() { + compileInput(''); - changeInputValueTo('stuff'); - expect(inputElm.val()).toBe('stuff'); - expect(scope.value).toBeUndefined(); - expect(inputElm).toBeInvalid(); + scope.$apply(function() { + scope.test = null; }); - it('should render as blank if null', function() { - compileInput(''); + expect(scope.test).toBeNull(); + expect(inputElm.val()).toEqual(''); + }); - scope.$apply(function() { - scope.test = null; - }); + it('should come up blank when no value specified', function() { + compileInput(''); - expect(scope.test).toBeNull(); - expect(inputElm.val()).toEqual(''); - }); + scope.$digest(); + expect(inputElm.val()).toBe(''); - it('should come up blank when no value specified', function() { - compileInput(''); + scope.$apply(function() { + scope.test = null; + }); - scope.$digest(); - expect(inputElm.val()).toBe(''); + expect(scope.test).toBeNull(); + expect(inputElm.val()).toBe(''); + }); - scope.$apply(function() { - scope.test = null; - }); - expect(scope.test).toBeNull(); - expect(inputElm.val()).toBe(''); - }); + it('should parse empty string to null', function() { + compileInput(''); + scope.$apply(function() { + scope.test = new Date(2011, 0, 1); + }); - it('should parse empty string to null', function() { - compileInput(''); + changeInputValueTo(''); + expect(scope.test).toBeNull(); + expect(inputElm).toBeValid(); + }); - scope.$apply(function() { - scope.test = new Date(2011, 0, 1); - }); + describe('min', function (){ + beforeEach(function (){ + compileInput(''); + scope.$digest(); + }); - changeInputValueTo(''); - expect(scope.test).toBeNull(); - expect(inputElm).toBeValid(); - }); + it('should invalidate', function (){ + changeInputValueTo('2012-W12'); + expect(inputElm).toBeInvalid(); + expect(scope.value).toBeFalsy(); + expect(scope.form.alias.$error.min).toBeTruthy(); + }); - describe('min', function (){ - beforeEach(function (){ - compileInput(''); - scope.$digest(); - }); + it('should validate', function (){ + changeInputValueTo('2013-W03'); + expect(inputElm).toBeValid(); + expect(+scope.value).toBe(+new Date(2013, 0, 17)); + expect(scope.form.alias.$error.min).toBeFalsy(); + }); + }); - it('should invalidate', function (){ - changeInputValueTo('2012-W12'); - expect(inputElm).toBeInvalid(); - expect(scope.value).toBeFalsy(); - expect(scope.form.alias.$error.min).toBeTruthy(); - }); + describe('max', function(){ + beforeEach(function (){ + compileInput(''); + scope.$digest(); + }); - it('should validate', function (){ - changeInputValueTo('2013-W03'); - expect(inputElm).toBeValid(); - expect(+scope.value).toBe(+new Date(2013, 0, 17)); - expect(scope.form.alias.$error.min).toBeFalsy(); - }); + it('should validate', function (){ + changeInputValueTo('2012-W01'); + expect(inputElm).toBeValid(); + expect(+scope.value).toBe(+new Date(2012, 0, 5)); + expect(scope.form.alias.$error.max).toBeFalsy(); }); - describe('max', function(){ - beforeEach(function (){ - compileInput(''); - scope.$digest(); - }); + it('should invalidate', function (){ + changeInputValueTo('2013-W03'); + expect(inputElm).toBeInvalid(); + expect(scope.value).toBeUndefined(); + expect(scope.form.alias.$error.max).toBeTruthy(); + }); + }); + }); - it('should validate', function (){ - changeInputValueTo('2012-W01'); - expect(inputElm).toBeValid(); - expect(+scope.value).toBe(+new Date(2012, 0, 5)); - expect(scope.form.alias.$error.max).toBeFalsy(); - }); + describe('datetime-local', function () { + it('should render blank if model is not a Date object', function() { + compileInput(''); - it('should invalidate', function (){ - changeInputValueTo('2013-W03'); - expect(inputElm).toBeInvalid(); - expect(scope.value).toBeUndefined(); - expect(scope.form.alias.$error.max).toBeTruthy(); - }); + scope.$apply(function(){ + scope.lunchtime = '2013-12-16T11:30'; }); - }); - describe('datetime-local', function () { - it('should render blank if model is not a Date object', function() { - compileInput(''); + expect(inputElm.val()).toBe(''); + }); - scope.$apply(function(){ - scope.lunchtime = '2013-12-16T11:30'; - }); + it('should set the view if the model if a valid Date object.', function(){ + compileInput(''); - expect(inputElm.val()).toBe(''); + scope.$apply(function (){ + scope.tenSecondsToNextYear = new Date(2013, 11, 31, 23, 59); }); - it('should set the view if the model if a valid Date object.', function(){ - compileInput(''); + expect(inputElm.val()).toBe('2013-12-31T23:59'); + }); - scope.$apply(function (){ - scope.tenSecondsToNextYear = new Date(2013, 11, 31, 23, 59); - }); + it('should set the model undefined if the view is invalid', function (){ + compileInput(''); - expect(inputElm.val()).toBe('2013-12-31T23:59'); + scope.$apply(function (){ + scope.breakMe = new Date(2009, 0, 6, 16, 25); }); - it('should set the model undefined if the view is invalid', function (){ - compileInput(''); + expect(inputElm.val()).toBe('2009-01-06T16:25'); - scope.$apply(function (){ - scope.breakMe = new Date(2009, 0, 6, 16, 25); - }); + try { + //set to text for browsers with datetime-local validation. + inputElm[0].setAttribute('type', 'text'); + } catch(e) { + //for IE8 + } - expect(inputElm.val()).toBe('2009-01-06T16:25'); + changeInputValueTo('stuff'); + expect(inputElm.val()).toBe('stuff'); + expect(scope.breakMe).toBeUndefined(); + expect(inputElm).toBeInvalid(); + }); - try { - //set to text for browsers with datetime-local validation. - inputElm[0].setAttribute('type', 'text'); - } catch(e) { - //for IE8 - } + it('should render as blank if null', function() { + compileInput(''); - changeInputValueTo('stuff'); - expect(inputElm.val()).toBe('stuff'); - expect(scope.breakMe).toBeUndefined(); - expect(inputElm).toBeInvalid(); + scope.$apply(function() { + scope.test = null; }); - it('should render as blank if null', function() { - compileInput(''); - - scope.$apply(function() { - scope.test = null; - }); - - expect(scope.test).toBeNull(); - expect(inputElm.val()).toEqual(''); - }); + expect(scope.test).toBeNull(); + expect(inputElm.val()).toEqual(''); + }); - it('should come up blank when no value specified', function() { - compileInput(''); + it('should come up blank when no value specified', function() { + compileInput(''); - scope.$digest(); - expect(inputElm.val()).toBe(''); + scope.$digest(); + expect(inputElm.val()).toBe(''); - scope.$apply(function() { - scope.test = null; - }); + scope.$apply(function() { + scope.test = null; + }); - expect(scope.test).toBeNull(); - expect(inputElm.val()).toBe(''); - }); + expect(scope.test).toBeNull(); + expect(inputElm.val()).toBe(''); + }); - it('should parse empty string to null', function() { - compileInput(''); + it('should parse empty string to null', function() { + compileInput(''); - scope.$apply(function() { - scope.test = new Date(2011, 0, 1); - }); + scope.$apply(function() { + scope.test = new Date(2011, 0, 1); + }); - changeInputValueTo(''); - expect(scope.test).toBeNull(); - expect(inputElm).toBeValid(); - }); + changeInputValueTo(''); + expect(scope.test).toBeNull(); + expect(inputElm).toBeValid(); + }); - describe('min', function (){ - beforeEach(function (){ - compileInput(''); - scope.$digest(); - }); + describe('min', function (){ + beforeEach(function (){ + compileInput(''); + scope.$digest(); + }); - it('should invalidate', function (){ - changeInputValueTo('1999-12-31T01:02'); - expect(inputElm).toBeInvalid(); - expect(scope.value).toBeFalsy(); - expect(scope.form.alias.$error.min).toBeTruthy(); - }); + it('should invalidate', function (){ + changeInputValueTo('1999-12-31T01:02'); + expect(inputElm).toBeInvalid(); + expect(scope.value).toBeFalsy(); + expect(scope.form.alias.$error.min).toBeTruthy(); + }); - it('should validate', function (){ - changeInputValueTo('2000-01-01T23:02'); - expect(inputElm).toBeValid(); - expect(+scope.value).toBe(+new Date(2000, 0, 1, 23, 2)); - expect(scope.form.alias.$error.min).toBeFalsy(); - }); + it('should validate', function (){ + changeInputValueTo('2000-01-01T23:02'); + expect(inputElm).toBeValid(); + expect(+scope.value).toBe(+new Date(2000, 0, 1, 23, 2)); + expect(scope.form.alias.$error.min).toBeFalsy(); }); + }); - describe('max', function (){ - beforeEach(function (){ - compileInput(''); - scope.$digest(); - }); + describe('max', function (){ + beforeEach(function (){ + compileInput(''); + scope.$digest(); + }); - it('should invalidate', function (){ - changeInputValueTo('2019-12-31T01:02'); - expect(inputElm).toBeInvalid(); - expect(scope.value).toBeFalsy(); - expect(scope.form.alias.$error.max).toBeTruthy(); - }); + it('should invalidate', function (){ + changeInputValueTo('2019-12-31T01:02'); + expect(inputElm).toBeInvalid(); + expect(scope.value).toBeFalsy(); + expect(scope.form.alias.$error.max).toBeTruthy(); + }); - it('should validate', function() { - changeInputValueTo('2000-01-01T01:02'); - expect(inputElm).toBeValid(); - expect(+scope.value).toBe(+new Date(2000, 0, 1, 1, 2)); - expect(scope.form.alias.$error.max).toBeFalsy(); - }); + it('should validate', function() { + changeInputValueTo('2000-01-01T01:02'); + expect(inputElm).toBeValid(); + expect(+scope.value).toBe(+new Date(2000, 0, 1, 1, 2)); + expect(scope.form.alias.$error.max).toBeFalsy(); }); + }); - it('should validate even if max value changes on-the-fly', function(done) { - scope.max = '2013-01-01T01:02'; - compileInput(''); - scope.$digest(); + it('should validate even if max value changes on-the-fly', function(done) { + scope.max = '2013-01-01T01:02'; + compileInput(''); + scope.$digest(); - changeInputValueTo('2014-01-01T12:34'); - expect(inputElm).toBeInvalid(); + changeInputValueTo('2014-01-01T12:34'); + expect(inputElm).toBeInvalid(); - scope.max = '2001-01-01T01:02'; - scope.$digest(function () { - expect(inputElm).toBeValid(); - done(); - }); + scope.max = '2001-01-01T01:02'; + scope.$digest(function () { + expect(inputElm).toBeValid(); + done(); }); + }); - it('should validate even if min value changes on-the-fly', function(done) { - scope.min = '2013-01-01T01:02'; - compileInput(''); - scope.$digest(); + it('should validate even if min value changes on-the-fly', function(done) { + scope.min = '2013-01-01T01:02'; + compileInput(''); + scope.$digest(); - changeInputValueTo('2010-01-01T12:34'); - expect(inputElm).toBeInvalid(); + changeInputValueTo('2010-01-01T12:34'); + expect(inputElm).toBeInvalid(); - scope.min = '2014-01-01T01:02'; - scope.$digest(function () { - expect(inputElm).toBeValid(); - done(); - }); + scope.min = '2014-01-01T01:02'; + scope.$digest(function () { + expect(inputElm).toBeValid(); + done(); }); - }); + }); + }); describe('time', function () { it('should render blank if model is not a Date object', function() { @@ -1510,44 +1513,44 @@ describe('input', function() { expect(inputElm).toBeInvalid(); }); - it('should render as blank if null', function() { - compileInput(''); - - scope.$apply(function() { - scope.test = null; - }); + it('should render as blank if null', function() { + compileInput(''); - expect(scope.test).toBeNull(); - expect(inputElm.val()).toEqual(''); + scope.$apply(function() { + scope.test = null; }); - it('should come up blank when no value specified', function() { - compileInput(''); + expect(scope.test).toBeNull(); + expect(inputElm.val()).toEqual(''); + }); - scope.$digest(); - expect(inputElm.val()).toBe(''); + it('should come up blank when no value specified', function() { + compileInput(''); - scope.$apply(function() { - scope.test = null; - }); + scope.$digest(); + expect(inputElm.val()).toBe(''); - expect(scope.test).toBeNull(); - expect(inputElm.val()).toBe(''); + scope.$apply(function() { + scope.test = null; }); + expect(scope.test).toBeNull(); + expect(inputElm.val()).toBe(''); + }); - it('should parse empty string to null', function() { - compileInput(''); - scope.$apply(function() { - scope.test = new Date(2011, 0, 1); - }); + it('should parse empty string to null', function() { + compileInput(''); - changeInputValueTo(''); - expect(scope.test).toBeNull(); - expect(inputElm).toBeValid(); + scope.$apply(function() { + scope.test = new Date(2011, 0, 1); }); + changeInputValueTo(''); + expect(scope.test).toBeNull(); + expect(inputElm).toBeValid(); + }); + describe('min', function (){ beforeEach(function (){ compileInput(''); @@ -1623,125 +1626,125 @@ describe('input', function() { describe('date', function () { it('should render blank if model is not a Date object.', function() { - compileInput(''); + compileInput(''); - scope.$apply(function(){ - scope.birthday = '1977-10-22'; - }); + scope.$apply(function(){ + scope.birthday = '1977-10-22'; + }); - expect(inputElm.val()).toBe(''); + expect(inputElm.val()).toBe(''); }); it('should set the view if the model if a valid Date object.', function(){ - compileInput(''); + compileInput(''); - scope.$apply(function (){ - scope.christmas = new Date(2013, 11, 25); - }); + scope.$apply(function (){ + scope.christmas = new Date(2013, 11, 25); + }); - expect(inputElm.val()).toBe('2013-12-25'); + expect(inputElm.val()).toBe('2013-12-25'); }); it('should set the model undefined if the view is invalid', function (){ - compileInput(''); + compileInput(''); - scope.$apply(function (){ - scope.arrMatey = new Date(2014, 8, 14); - }); + scope.$apply(function (){ + scope.arrMatey = new Date(2014, 8, 14); + }); - expect(inputElm.val()).toBe('2014-09-14'); + expect(inputElm.val()).toBe('2014-09-14'); - try { - //set to text for browsers with date validation. - inputElm[0].setAttribute('type', 'text'); - } catch(e) { - //for IE8 - } + try { + //set to text for browsers with date validation. + inputElm[0].setAttribute('type', 'text'); + } catch(e) { + //for IE8 + } - changeInputValueTo('1-2-3'); - expect(inputElm.val()).toBe('1-2-3'); - expect(scope.arrMatey).toBeUndefined(); - expect(inputElm).toBeInvalid(); + changeInputValueTo('1-2-3'); + expect(inputElm.val()).toBe('1-2-3'); + expect(scope.arrMatey).toBeUndefined(); + expect(inputElm).toBeInvalid(); }); - it('should render as blank if null', function() { - compileInput(''); - - scope.$apply(function() { - scope.test = null; - }); + it('should render as blank if null', function() { + compileInput(''); - expect(scope.test).toBeNull(); - expect(inputElm.val()).toEqual(''); + scope.$apply(function() { + scope.test = null; }); - it('should come up blank when no value specified', function() { - compileInput(''); + expect(scope.test).toBeNull(); + expect(inputElm.val()).toEqual(''); + }); - scope.$digest(); - expect(inputElm.val()).toBe(''); + it('should come up blank when no value specified', function() { + compileInput(''); - scope.$apply(function() { - scope.test = null; - }); + scope.$digest(); + expect(inputElm.val()).toBe(''); - expect(scope.test).toBeNull(); - expect(inputElm.val()).toBe(''); + scope.$apply(function() { + scope.test = null; }); + expect(scope.test).toBeNull(); + expect(inputElm.val()).toBe(''); + }); - it('should parse empty string to null', function() { - compileInput(''); - scope.$apply(function() { - scope.test = new Date(2011, 0, 1); - }); + it('should parse empty string to null', function() { + compileInput(''); - changeInputValueTo(''); - expect(scope.test).toBeNull(); - expect(inputElm).toBeValid(); + scope.$apply(function() { + scope.test = new Date(2011, 0, 1); }); + changeInputValueTo(''); + expect(scope.test).toBeNull(); + expect(inputElm).toBeValid(); + }); + describe('min', function (){ - beforeEach(function (){ - compileInput(''); - scope.$digest(); - }); + beforeEach(function (){ + compileInput(''); + scope.$digest(); + }); - it('should invalidate', function (){ - changeInputValueTo('1999-12-31'); - expect(inputElm).toBeInvalid(); - expect(scope.value).toBeFalsy(); - expect(scope.form.alias.$error.min).toBeTruthy(); - }); + it('should invalidate', function (){ + changeInputValueTo('1999-12-31'); + expect(inputElm).toBeInvalid(); + expect(scope.value).toBeFalsy(); + expect(scope.form.alias.$error.min).toBeTruthy(); + }); - it('should validate', function (){ - changeInputValueTo('2000-01-01'); - expect(inputElm).toBeValid(); - expect(+scope.value).toBe(+new Date(2000, 0, 1)); - expect(scope.form.alias.$error.min).toBeFalsy(); - }); + it('should validate', function (){ + changeInputValueTo('2000-01-01'); + expect(inputElm).toBeValid(); + expect(+scope.value).toBe(+new Date(2000, 0, 1)); + expect(scope.form.alias.$error.min).toBeFalsy(); + }); }); describe('max', function (){ - beforeEach(function (){ - compileInput(''); - scope.$digest(); - }); + beforeEach(function (){ + compileInput(''); + scope.$digest(); + }); - it('should invalidate', function (){ - changeInputValueTo('2019-12-31'); - expect(inputElm).toBeInvalid(); - expect(scope.value).toBeFalsy(); - expect(scope.form.alias.$error.max).toBeTruthy(); - }); + it('should invalidate', function (){ + changeInputValueTo('2019-12-31'); + expect(inputElm).toBeInvalid(); + expect(scope.value).toBeFalsy(); + expect(scope.form.alias.$error.max).toBeTruthy(); + }); - it('should validate', function() { - changeInputValueTo('2000-01-01'); - expect(inputElm).toBeValid(); - expect(+scope.value).toBe(+new Date(2000, 0, 1)); - expect(scope.form.alias.$error.max).toBeFalsy(); - }); + it('should validate', function() { + changeInputValueTo('2000-01-01'); + expect(inputElm).toBeValid(); + expect(+scope.value).toBe(+new Date(2000, 0, 1)); + expect(scope.form.alias.$error.max).toBeFalsy(); + }); }); it('should validate even if max value changes on-the-fly', function(done) { @@ -1754,24 +1757,24 @@ describe('input', function() { scope.max = '2001-01-01'; scope.$digest(function () { - expect(inputElm).toBeValid(); - done(); + expect(inputElm).toBeValid(); + done(); }); }); it('should validate even if min value changes on-the-fly', function(done) { - scope.min = '2013-01-01'; - compileInput(''); - scope.$digest(); + scope.min = '2013-01-01'; + compileInput(''); + scope.$digest(); - changeInputValueTo('2010-01-01'); - expect(inputElm).toBeInvalid(); + changeInputValueTo('2010-01-01'); + expect(inputElm).toBeInvalid(); - scope.min = '2014-01-01'; - scope.$digest(function () { - expect(inputElm).toBeValid(); - done(); - }); + scope.min = '2014-01-01'; + scope.$digest(function () { + expect(inputElm).toBeValid(); + done(); + }); }); }); @@ -1925,7 +1928,7 @@ describe('input', function() { }); expect(inputElm).toBeValid(); - expect(inputElm.val()).toBe('0') + expect(inputElm.val()).toBe('0'); expect(scope.form.alias.$error.required).toBeFalsy(); }); @@ -1962,7 +1965,7 @@ describe('input', function() { describe('EMAIL_REGEXP', function() { - + /* global EMAIL_REGEXP: false */ it('should validate email', function() { expect(EMAIL_REGEXP.test('a@b.com')).toBe(true); expect(EMAIL_REGEXP.test('a@b.museum')).toBe(true); @@ -1992,7 +1995,7 @@ describe('input', function() { describe('URL_REGEXP', function() { - + /* global URL_REGEXP: false */ it('should validate url', function() { expect(URL_REGEXP.test('http://server:123/path')).toBe(true); expect(URL_REGEXP.test('a@B.c')).toBe(false); @@ -2507,7 +2510,7 @@ describe('NgModel animations', function() { } } return animations; - }; + } function assertValidAnimation(animation, event, className) { expect(animation.event).toBe(event); diff --git a/test/ng/directive/ngClassSpec.js b/test/ng/directive/ngClassSpec.js index 3b485ba24894..74de76d6555d 100644 --- a/test/ng/directive/ngClassSpec.js +++ b/test/ng/directive/ngClassSpec.js @@ -72,7 +72,8 @@ describe('ngClass', function() { $rootScope.$digest(); expect(element.hasClass('A')).toBeFalsy(); expect(element.hasClass('B')).toBeTruthy(); - })); + }) + ); it('should support adding multiple classes via a space delimited string', inject(function($rootScope, $compile) { @@ -203,7 +204,8 @@ describe('ngClass', function() { expect(e1.hasClass('odd')).toBeTruthy(); expect(e2.hasClass('same')).toBeTruthy(); expect(e2.hasClass('odd')).toBeTruthy(); - })); + }) + ); it('should allow both ngClass and ngClassOdd/Even with multiple classes', inject(function($rootScope, $compile) { element = $compile('