diff --git a/test/.eslintrc.json b/test/.eslintrc.json index 007b458949ad..cb6b29f75dae 100644 --- a/test/.eslintrc.json +++ b/test/.eslintrc.json @@ -176,6 +176,7 @@ "browserSupportsCssAnimations": false, "browserTrigger": false, "jqLiteCacheSize": false, - "createAsync": false + "createAsync": false, + "support": false } } diff --git a/test/auto/injectorSpec.js b/test/auto/injectorSpec.js index 2cdb34ed1675..bf8fe284e7ed 100644 --- a/test/auto/injectorSpec.js +++ b/test/auto/injectorSpec.js @@ -1,7 +1,5 @@ 'use strict'; -/* globals support: false */ - describe('injector.modules', function() { it('should expose the loaded module info on the instance injector', function() { var test1 = angular.module('test1', ['test2']).info({ version: '1.1' }); @@ -327,26 +325,24 @@ describe('injector', function() { expect(instance.aVal()).toEqual('a-value'); }); - if (/chrome/.test(window.navigator.userAgent)) { - they('should detect ES6 classes regardless of whitespace/comments ($prop)', [ - 'class Test {}', - 'class Test{}', - 'class //<--ES6 stuff\nTest {}', - 'class//<--ES6 stuff\nTest {}', - 'class {}', - 'class{}', - 'class //<--ES6 stuff\n {}', - 'class//<--ES6 stuff\n {}', - 'class/* Test */{}', - 'class /* Test */ {}' - ], function(classDefinition) { - // eslint-disable-next-line no-eval - var Clazz = eval('(' + classDefinition + ')'); - var instance = injector.invoke(Clazz); - - expect(instance).toEqual(jasmine.any(Clazz)); - }); - } + they('should detect ES6 classes regardless of whitespace/comments ($prop)', [ + 'class Test {}', + 'class Test{}', + 'class //<--ES6 stuff\nTest {}', + 'class//<--ES6 stuff\nTest {}', + 'class {}', + 'class{}', + 'class //<--ES6 stuff\n {}', + 'class//<--ES6 stuff\n {}', + 'class/* Test */{}', + 'class /* Test */ {}' + ], function(classDefinition) { + // eslint-disable-next-line no-eval + var Clazz = eval('(' + classDefinition + ')'); + var instance = injector.invoke(Clazz); + + expect(instance).toEqual(jasmine.any(Clazz)); + }); } }); diff --git a/test/helpers/testabilityPatch.js b/test/helpers/testabilityPatch.js index 06ee2aa79399..87a4ecaeb534 100644 --- a/test/helpers/testabilityPatch.js +++ b/test/helpers/testabilityPatch.js @@ -4,7 +4,7 @@ if (window.bindJQuery) bindJQuery(); var supportTests = { - classes: '(class {})', + classes: '/^class\\b/.test((class C {}).toString())', fatArrow: 'a => a', ES6Function: '({ fn(x) { return; } })' }; @@ -15,8 +15,7 @@ for (var prop in supportTests) { if (supportTests.hasOwnProperty(prop)) { try { // eslint-disable-next-line no-eval - eval(supportTests[prop]); - support[prop] = true; + support[prop] = !!eval(supportTests[prop]); } catch (e) { support[prop] = false; } diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index b87a7e7df9dd..62bd5841f3e8 100644 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -6175,10 +6175,10 @@ describe('$compile', function() { }); it('should eventually expose isolate scope variables on ES6 class controller with controllerAs when bindToController is true', function() { - if (!/chrome/i.test(window.navigator.userAgent)) return; + if (!support.classes) return; var controllerCalled = false; // eslint-disable-next-line no-eval - var Controller = eval( + var Controller = eval('(\n' + 'class Foo {\n' + ' constructor($scope) {}\n' + ' $onInit() {\n' + @@ -6194,7 +6194,8 @@ describe('$compile', function() { ' expect(this.fn()).toBe(\'called!\');\n' + ' controllerCalled = true;\n' + ' }\n' + - '}'); + '}\n' + + ')'); spyOn(Controller.prototype, '$onInit').and.callThrough(); module(function($compileProvider) { diff --git a/test/ngMock/angular-mocksSpec.js b/test/ngMock/angular-mocksSpec.js index 4bfad9d3bb10..67f9674f8034 100644 --- a/test/ngMock/angular-mocksSpec.js +++ b/test/ngMock/angular-mocksSpec.js @@ -2100,7 +2100,7 @@ describe('ngMock', function() { ); - if (/chrome/.test(window.navigator.userAgent)) { + if (support.classes) { it('should support assigning bindings to class-based controller', function() { var called = false; var data = [