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

Commit f3151be

Browse files
committed
test(support): verify support tests results in all tested browsers
1 parent 33cd29b commit f3151be

File tree

4 files changed

+107
-25
lines changed

4 files changed

+107
-25
lines changed

test/auto/injectorSpec.js

Lines changed: 5 additions & 5 deletions
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

Lines changed: 20 additions & 0 deletions
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/testabilityPatch.js

Lines changed: 0 additions & 20 deletions
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

test/ng/supportSpec.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
'use strict';
2+
3+
describe('support test results', function() {
4+
var expected, version, testName;
5+
var userAgent = window.navigator.userAgent;
6+
7+
if (/edge\//i.test(userAgent)) {
8+
expected = {
9+
classes: true,
10+
fatArrows: true,
11+
shorthandMethods: true
12+
};
13+
} else if (/(?:msie|trident)/i.test(userAgent)) {
14+
expected = {
15+
classes: false,
16+
fatArrows: false,
17+
shorthandMethods: false
18+
};
19+
} else if (/chrome/i.test(userAgent)) {
20+
// Catches Chrome on Android as well (i.e. the default
21+
// Android browser on Android >= 4.4).
22+
expected = {
23+
classes: true,
24+
fatArrows: true,
25+
shorthandMethods: true
26+
};
27+
} else if (/\b9\.\d+(\.\d+)* safari/i.test(userAgent)) {
28+
expected = {
29+
classes: true,
30+
fatArrows: false,
31+
shorthandMethods: true
32+
};
33+
} else if (/\b\d+\.\d+(\.\d+)* safari/i.test(userAgent)) {
34+
expected = {
35+
classes: true,
36+
fatArrows: true,
37+
shorthandMethods: true
38+
};
39+
} else if (/firefox/i.test(userAgent)) {
40+
version = parseInt(userAgent.match(/firefox\/(\d+)/i)[1], 10);
41+
expected = {
42+
classes: version >= 55,
43+
fatArrows: true,
44+
shorthandMethods: true
45+
};
46+
} else if (/iphone os [78]_/i.test(userAgent)) {
47+
expected = {
48+
classes: false,
49+
fatArrows: false,
50+
shorthandMethods: false
51+
};
52+
} else if (/iphone os 9_/i.test(userAgent)) {
53+
expected = {
54+
classes: true,
55+
fatArrows: false,
56+
shorthandMethods: true
57+
};
58+
} else if (/iphone os/i.test(userAgent)) {
59+
expected = {
60+
classes: true,
61+
fatArrows: true,
62+
shorthandMethods: true
63+
};
64+
} else if (/android 4\.[0-3]/i.test(userAgent)) {
65+
expected = {
66+
classes: false,
67+
fatArrows: false,
68+
shorthandMethods: false
69+
};
70+
}
71+
72+
it('should have expected values specified', function() {
73+
expect(expected).not.toBe(null);
74+
expect(typeof expected).toBe('object');
75+
});
76+
77+
for (testName in expected) {
78+
it('should report support.' + testName + ' to be ' + expected[testName], function() {
79+
expect(support[testName]).toBe(expected[testName]);
80+
});
81+
}
82+
});

0 commit comments

Comments
 (0)