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

Commit 65dab7a

Browse files
committed
chore(test): refactor test conditionals
1 parent 4444539 commit 65dab7a

File tree

4 files changed

+37
-42
lines changed

4 files changed

+37
-42
lines changed

Diff for: test/patch/HTMLImports.spec.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
'use strict';
22

3-
describe('HTML Imports', function () {
4-
if (!supportsImports()) {
5-
console.log('WARNING: HTML Imports test (missing this API)');
6-
return;
7-
}
3+
describe('HTML Imports', ifEnvSupports(supportsImports, function () {
84

95
var flag, hasParent;
106

@@ -79,8 +75,9 @@ describe('HTML Imports', function () {
7975
return flag;
8076
}
8177

82-
});
78+
}));
8379

8480
function supportsImports() {
8581
return 'import' in document.createElement('link');
8682
}
83+
supportsImports.message = 'HTML Imports';

Diff for: test/patch/MutationObserver.spec.js

+4-29
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
'use strict';
22

3-
describe('MutationObserver', function () {
3+
describe('MutationObserver', ifEnvSupports('MutationObserver', function () {
44
var elt;
55

66
beforeEach(function () {
77
elt = document.createElement('div');
88
});
99

1010
it('should work', function () {
11-
if (!window.MutationObserver) {
12-
console.log('WARNING: skipping MutationObserver test (missing this API)');
13-
return;
14-
}
15-
1611
var flag = false,
1712
hasParent;
1813

@@ -40,11 +35,6 @@ describe('MutationObserver', function () {
4035
});
4136

4237
it('should dequeue upon disconnect', function () {
43-
if (!window.MutationObserver) {
44-
console.log('WARNING: skipping MutationObserver test (missing this API)');
45-
return;
46-
}
47-
4838
var flag = false,
4939
childZone = zone.fork({
5040
dequeueTask: function () {
@@ -63,11 +53,6 @@ describe('MutationObserver', function () {
6353
});
6454

6555
it('should enqueue once upon observation', function () {
66-
if (!window.MutationObserver) {
67-
console.log('WARNING: skipping MutationObserver test (missing this API)');
68-
return;
69-
}
70-
7156
var count = 0,
7257
childZone = zone.fork({
7358
enqueueTask: function () {
@@ -88,11 +73,6 @@ describe('MutationObserver', function () {
8873
});
8974

9075
it('should only dequeue upon disconnect if something is observed', function () {
91-
if (!window.MutationObserver) {
92-
console.log('WARNING: skipping MutationObserver test (missing this API)');
93-
return;
94-
}
95-
9676
var flag = false,
9777
elt = document.createElement('div'),
9878
childZone = zone.fork({
@@ -108,15 +88,10 @@ describe('MutationObserver', function () {
10888
});
10989

11090
});
111-
});
91+
}));
11292

113-
describe('WebKitMutationObserver', function () {
93+
describe('WebKitMutationObserver', ifEnvSupports('WebKitMutationObserver', function () {
11494
it('should ensure observers run within the zone', function () {
115-
if (!window.WebKitMutationObserver) {
116-
console.log('WARNING: skipping WebKitMutationObserver test (missing this API)');
117-
return;
118-
}
119-
12095
var flag = false,
12196
elt = document.createElement('div'),
12297
hasParent;
@@ -143,4 +118,4 @@ describe('WebKitMutationObserver', function () {
143118
});
144119

145120
});
146-
});
121+
}));

Diff for: test/patch/registerElement.spec.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@
55

66
'use strict';
77

8-
describe('document.registerElement', function () {
9-
if (!('registerElement' in document)) {
10-
console.log('WARNING: skipping document.registerElement test (missing this API)');
11-
return;
12-
}
13-
8+
describe('document.registerElement', ifEnvSupports(registerElement, function () {
149
var flag, hasParent;
1510

1611
// register a custom element for each callback
@@ -156,4 +151,9 @@ describe('document.registerElement', function () {
156151
});
157152
});
158153

159-
});
154+
}));
155+
156+
function registerElement() {
157+
return ('registerElement' in document);
158+
}
159+
registerElement.message = 'document.registerElement';

Diff for: test/util.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
/*
3+
* usage:
4+
5+
describe('whatever', run(function () {
6+
7+
}, function () {
8+
return 'registerElement'
9+
}, 'does not support whatevs'))
10+
11+
*/
12+
function ifEnvSupports(test, block) {
13+
return function () {
14+
var message = (test.message || test.name || test);
15+
if (typeof test === 'string' ? !!window[test] : test()) {
16+
block();
17+
} else {
18+
it('should skip the test if the API does not exist', function () {
19+
console.log('WARNING: skipping ' + message + ' tests (missing this API)');
20+
});
21+
}
22+
};
23+
};

0 commit comments

Comments
 (0)