Skip to content

Commit b4651e5

Browse files
authored
test(support): verify support tests results in all tested browsers (angular#16008)
Closes angular#16008
1 parent aef3ef7 commit b4651e5

File tree

4 files changed

+122
-25
lines changed

4 files changed

+122
-25
lines changed

test/auto/injectorSpec.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -283,32 +283,32 @@ describe('injector', function() {
283283

284284

285285
describe('es6', function() {
286-
if (support.ES6Function) {
286+
if (support.shorthandMethods) {
287287
// The functions are generated using `eval` as just having the ES6 syntax can break some browsers.
288-
it('should be possible to annotate functions that are declared using ES6 syntax', function() {
288+
it('should be possible to annotate shorthand methods', function() {
289289
// eslint-disable-next-line no-eval
290290
expect(annotate(eval('({ fn(x) { return; } })').fn)).toEqual(['x']);
291291
});
292292
}
293293

294294

295-
if (support.fatArrow) {
295+
if (support.fatArrows) {
296296
it('should create $inject for arrow functions', function() {
297297
// eslint-disable-next-line no-eval
298298
expect(annotate(eval('(a, b) => a'))).toEqual(['a', 'b']);
299299
});
300300
}
301301

302302

303-
if (support.fatArrow) {
303+
if (support.fatArrows) {
304304
it('should create $inject for arrow functions with no parenthesis', function() {
305305
// eslint-disable-next-line no-eval
306306
expect(annotate(eval('a => a'))).toEqual(['a']);
307307
});
308308
}
309309

310310

311-
if (support.fatArrow) {
311+
if (support.fatArrows) {
312312
it('should take args before first arrow', function() {
313313
// eslint-disable-next-line no-eval
314314
expect(annotate(eval('a => b => b'))).toEqual(['a']);

test/helpers/support.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
var supportTests = {
4+
classes: '/^class\\b/.test((class C {}).toString())',
5+
fatArrows: 'a => a',
6+
shorthandMethods: '({ fn(x) { return; } })'
7+
};
8+
9+
var support = {};
10+
11+
for (var prop in supportTests) {
12+
if (supportTests.hasOwnProperty(prop)) {
13+
try {
14+
// eslint-disable-next-line no-eval
15+
support[prop] = !!eval(supportTests[prop]);
16+
} catch (e) {
17+
support[prop] = false;
18+
}
19+
}
20+
}

test/helpers/supportSpec.js

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
'use strict';
2+
3+
describe('support test results', function() {
4+
var expected, version, testName;
5+
var userAgent = window.navigator.userAgent;
6+
7+
// Support: iOS 8 only
8+
if (/iPhone OS 10_1\d(?:_\d+)? /.test(userAgent)) {
9+
// iOS 8 official simulators have broken user agent (containing something like `iPhone OS 10_12_5`,
10+
// i.e. the macOS version in place of the iOS version) so they'd fall into an incorrect bucket.
11+
// Fix the user agent there.
12+
// NOTE: Make sure the above check doesn't catch the real iOS 10!
13+
userAgent = userAgent.replace(/iPhone OS 10(?:_\d+)+/, 'iPhone OS 8_1');
14+
}
15+
16+
if (/edge\//i.test(userAgent)) {
17+
expected = {
18+
classes: true,
19+
fatArrows: true,
20+
shorthandMethods: true
21+
};
22+
} else if (/msie|trident/i.test(userAgent)) {
23+
expected = {
24+
classes: false,
25+
fatArrows: false,
26+
shorthandMethods: false
27+
};
28+
} else if (/iphone os [78]_/i.test(userAgent)) {
29+
expected = {
30+
classes: false,
31+
fatArrows: false,
32+
shorthandMethods: false
33+
};
34+
} else if (/iphone os 9_/i.test(userAgent)) {
35+
expected = {
36+
classes: true,
37+
fatArrows: false,
38+
shorthandMethods: true
39+
};
40+
} else if (/iphone os/i.test(userAgent)) {
41+
expected = {
42+
classes: true,
43+
fatArrows: true,
44+
shorthandMethods: true
45+
};
46+
} else if (/android 4\.[0-3]/i.test(userAgent)) {
47+
expected = {
48+
classes: false,
49+
fatArrows: false,
50+
shorthandMethods: false
51+
};
52+
} else if (/chrome/i.test(userAgent)) {
53+
// Catches Chrome on Android as well (i.e. the default
54+
// Android browser on Android >= 4.4).
55+
expected = {
56+
classes: true,
57+
fatArrows: true,
58+
shorthandMethods: true
59+
};
60+
} else if (/firefox/i.test(userAgent)) {
61+
version = parseInt(userAgent.match(/firefox\/(\d+)/i)[1], 10);
62+
expected = {
63+
classes: version >= 55,
64+
fatArrows: true,
65+
shorthandMethods: true
66+
};
67+
} else if (/\b8(?:\.\d+)+ safari/i.test(userAgent)) {
68+
expected = {
69+
classes: false,
70+
fatArrows: false,
71+
shorthandMethods: false
72+
};
73+
} else if (/\b9(?:\.\d+)+ safari/i.test(userAgent)) {
74+
expected = {
75+
classes: true,
76+
fatArrows: false,
77+
shorthandMethods: true
78+
};
79+
} else if (/\b\d+(?:\.\d+)+ safari/i.test(userAgent)) {
80+
expected = {
81+
classes: true,
82+
fatArrows: true,
83+
shorthandMethods: true
84+
};
85+
}
86+
87+
it('should have expected values specified', function() {
88+
expect(expected).not.toBe(null);
89+
expect(typeof expected).toBe('object');
90+
});
91+
92+
for (testName in expected) {
93+
it('should report support.' + testName + ' to be ' + expected[testName], function() {
94+
expect(support[testName]).toBe(expected[testName]);
95+
});
96+
}
97+
});

test/helpers/testabilityPatch.js

-20
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,6 @@
33

44
if (window.bindJQuery) bindJQuery();
55

6-
var supportTests = {
7-
classes: '/^class\\b/.test((class C {}).toString())',
8-
fatArrow: 'a => a',
9-
ES6Function: '({ fn(x) { return; } })'
10-
};
11-
12-
var support = {};
13-
14-
for (var prop in supportTests) {
15-
if (supportTests.hasOwnProperty(prop)) {
16-
try {
17-
// eslint-disable-next-line no-eval
18-
support[prop] = !!eval(supportTests[prop]);
19-
} catch (e) {
20-
support[prop] = false;
21-
}
22-
}
23-
}
24-
25-
266
beforeEach(function() {
277

288
// all this stuff is not needed for module tests, where jqlite and publishExternalAPI and jqLite are not global vars

0 commit comments

Comments
 (0)