Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

test(*): run class-related tests everywhere; fix eval syntax #15967

Merged
merged 1 commit into from
May 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion test/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"browserSupportsCssAnimations": false,
"browserTrigger": false,
"jqLiteCacheSize": false,
"createAsync": false
"createAsync": false,
"support": false
}
}
40 changes: 18 additions & 22 deletions test/auto/injectorSpec.js
Original file line number Diff line number Diff line change
@@ -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' });
Expand Down Expand Up @@ -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));
});
}
});

Expand Down
5 changes: 2 additions & 3 deletions test/helpers/testabilityPatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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; } })'
};
Expand All @@ -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;
}
Expand Down
7 changes: 4 additions & 3 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' +
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/ngMock/angular-mocksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down