Skip to content

Commit 30eb194

Browse files
authored
test(*): run class-related tests everywhere; fix eval syntax
1. Wrap an evaled class definition in parens; previously they weren't; the test wasn't failing only because it was disabled everywhere outside of Chrome and Chrome <59 incorrectly accepted such input. 2. There's no reason to restrict class-related tests just to Chrome; now they run in every browser that supports ES6 classes. The classes support test was modified to check not only if a class definition parses but also if it stringifies correctly which is required by AngularJS. This restriction disables class-related tests in current Firefox (53) but will work in v55 or newer. Closes angular#15967
1 parent 2f3bd89 commit 30eb194

File tree

5 files changed

+27
-30
lines changed

5 files changed

+27
-30
lines changed

test/.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@
176176
"browserSupportsCssAnimations": false,
177177
"browserTrigger": false,
178178
"jqLiteCacheSize": false,
179-
"createAsync": false
179+
"createAsync": false,
180+
"support": false
180181
}
181182
}

test/auto/injectorSpec.js

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
/* globals support: false */
4-
53
describe('injector.modules', function() {
64
it('should expose the loaded module info on the instance injector', function() {
75
var test1 = angular.module('test1', ['test2']).info({ version: '1.1' });
@@ -327,26 +325,24 @@ describe('injector', function() {
327325
expect(instance.aVal()).toEqual('a-value');
328326
});
329327

330-
if (/chrome/.test(window.navigator.userAgent)) {
331-
they('should detect ES6 classes regardless of whitespace/comments ($prop)', [
332-
'class Test {}',
333-
'class Test{}',
334-
'class //<--ES6 stuff\nTest {}',
335-
'class//<--ES6 stuff\nTest {}',
336-
'class {}',
337-
'class{}',
338-
'class //<--ES6 stuff\n {}',
339-
'class//<--ES6 stuff\n {}',
340-
'class/* Test */{}',
341-
'class /* Test */ {}'
342-
], function(classDefinition) {
343-
// eslint-disable-next-line no-eval
344-
var Clazz = eval('(' + classDefinition + ')');
345-
var instance = injector.invoke(Clazz);
346-
347-
expect(instance).toEqual(jasmine.any(Clazz));
348-
});
349-
}
328+
they('should detect ES6 classes regardless of whitespace/comments ($prop)', [
329+
'class Test {}',
330+
'class Test{}',
331+
'class //<--ES6 stuff\nTest {}',
332+
'class//<--ES6 stuff\nTest {}',
333+
'class {}',
334+
'class{}',
335+
'class //<--ES6 stuff\n {}',
336+
'class//<--ES6 stuff\n {}',
337+
'class/* Test */{}',
338+
'class /* Test */ {}'
339+
], function(classDefinition) {
340+
// eslint-disable-next-line no-eval
341+
var Clazz = eval('(' + classDefinition + ')');
342+
var instance = injector.invoke(Clazz);
343+
344+
expect(instance).toEqual(jasmine.any(Clazz));
345+
});
350346
}
351347
});
352348

test/helpers/testabilityPatch.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
if (window.bindJQuery) bindJQuery();
55

66
var supportTests = {
7-
classes: '(class {})',
7+
classes: '/^class\\b/.test((class C {}).toString())',
88
fatArrow: 'a => a',
99
ES6Function: '({ fn(x) { return; } })'
1010
};
@@ -15,8 +15,7 @@ for (var prop in supportTests) {
1515
if (supportTests.hasOwnProperty(prop)) {
1616
try {
1717
// eslint-disable-next-line no-eval
18-
eval(supportTests[prop]);
19-
support[prop] = true;
18+
support[prop] = !!eval(supportTests[prop]);
2019
} catch (e) {
2120
support[prop] = false;
2221
}

test/ng/compileSpec.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6175,10 +6175,10 @@ describe('$compile', function() {
61756175
});
61766176

61776177
it('should eventually expose isolate scope variables on ES6 class controller with controllerAs when bindToController is true', function() {
6178-
if (!/chrome/i.test(window.navigator.userAgent)) return;
6178+
if (!support.classes) return;
61796179
var controllerCalled = false;
61806180
// eslint-disable-next-line no-eval
6181-
var Controller = eval(
6181+
var Controller = eval('(\n' +
61826182
'class Foo {\n' +
61836183
' constructor($scope) {}\n' +
61846184
' $onInit() {\n' +
@@ -6194,7 +6194,8 @@ describe('$compile', function() {
61946194
' expect(this.fn()).toBe(\'called!\');\n' +
61956195
' controllerCalled = true;\n' +
61966196
' }\n' +
6197-
'}');
6197+
'}\n' +
6198+
')');
61986199
spyOn(Controller.prototype, '$onInit').and.callThrough();
61996200

62006201
module(function($compileProvider) {

test/ngMock/angular-mocksSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2100,7 +2100,7 @@ describe('ngMock', function() {
21002100
);
21012101

21022102

2103-
if (/chrome/.test(window.navigator.userAgent)) {
2103+
if (support.classes) {
21042104
it('should support assigning bindings to class-based controller', function() {
21052105
var called = false;
21062106
var data = [

0 commit comments

Comments
 (0)