Skip to content

Commit 242e4ed

Browse files
authored
Merge pull request #40 from PolymerElements/shady-dom-flush
force synchrony for ShadyDOM
2 parents a247b55 + 5128734 commit 242e4ed

File tree

4 files changed

+29
-16
lines changed

4 files changed

+29
-16
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"devDependencies": {
1212
"web-component-tester": "^4.0.0",
1313
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0",
14-
"webcomponentsjs-v1": "webcomponents/webcomponentsjs#v1-polymer-edits"
14+
"webcomponentsjs-v1": "webcomponents/webcomponentsjs#v1"
1515
},
1616
"main": "test-fixture.html",
1717
"ignore": []

test-fixture.html

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,18 @@
235235

236236
forcePolyfillAttachedStateSynchrony: function () {
237237
// Force synchrony in attachedCallback and detachedCallback where
238-
// implemented, in the event that we are dealing with the async Web
239-
// Components Polyfill.
240-
if (window.CustomElements && window.CustomElements.takeRecords) {
238+
// implemented, in the event that we are dealing with one of these async
239+
// polyfills:
240+
// 1. Web Components CustomElements polyfill (v1 or v0).
241+
if (window.customElements && window.customElements.flush) {
242+
window.customElements.flush();
243+
} else if (window.CustomElements && window.CustomElements.takeRecords) {
241244
window.CustomElements.takeRecords();
242245
}
246+
// 2. ShadyDOM polyfill.
247+
if (window.ShadyDOM) {
248+
window.ShadyDOM.flush();
249+
}
243250
},
244251

245252
collectElementChildren: function (parent) {

test/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
1616
<script src="../../web-component-tester/browser.js"></script>
1717

18-
<link rel="import" href="../../polymer/polymer.html">
19-
2018
</head>
2119
<body>
2220
<script>
2321
WCT.loadSuites([
24-
'test-fixture.html',
25-
'test-fixture-v1.html',
26-
'handle-multiple-registrations.html'
22+
'test-fixture.html', // shady
23+
'test-fixture.html?dom=shadow', // shadow
24+
'test-fixture-v1.html?wc-shadydom=true&wc-ce=true', // shady
25+
'test-fixture-v1.html', // shadow
26+
'handle-multiple-registrations.html',
2727
]);
2828
</script>
2929
</body>

test/test-fixture-v1.html

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
<head>
1313
<title>test-fixture</title>
1414

15+
<script>
16+
// Save original HTMLElement constructor since customElements v1 polyfill
17+
// overrides it https://github.com/webcomponents/webcomponentsjs/issues/623
18+
var _HTMLElement = window.HTMLElement;
19+
</script>
20+
1521
<script src="../../webcomponentsjs-v1/webcomponents-lite.js"></script>
1622
<script src="../../web-component-tester/browser.js"></script>
1723

@@ -173,7 +179,7 @@
173179

174180
describe('for a dom with a single root element', function () {
175181
it('returns a reference to the root element', function () {
176-
expect(el).to.be.instanceOf(HTMLElement);
182+
expect(el).to.be.instanceOf(_HTMLElement);
177183
});
178184
});
179185

@@ -192,8 +198,8 @@
192198

193199
it('returns an array of root elements', function () {
194200
expect(els).to.be.instanceOf(Array);
195-
expect(els[0]).to.be.instanceOf(HTMLElement);
196-
expect(els[1]).to.be.instanceOf(HTMLElement);
201+
expect(els[0]).to.be.instanceOf(_HTMLElement);
202+
expect(els[1]).to.be.instanceOf(_HTMLElement);
197203
});
198204
});
199205

@@ -211,10 +217,10 @@
211217

212218
it('returns an array with elements grouped by template', function () {
213219
expect(groups).to.be.instanceOf(Array);
214-
expect(groups[0]).to.be.instanceOf(HTMLElement);
220+
expect(groups[0]).to.be.instanceOf(_HTMLElement);
215221
expect(groups[1]).to.be.instanceOf(Array);
216-
expect(groups[1][0]).to.be.instanceOf(HTMLElement);
217-
expect(groups[1][1]).to.be.instanceOf(HTMLElement);
222+
expect(groups[1][0]).to.be.instanceOf(_HTMLElement);
223+
expect(groups[1][1]).to.be.instanceOf(_HTMLElement);
218224
});
219225
});
220226

@@ -228,7 +234,7 @@
228234
});
229235

230236
it('returns a single element if the template has a single child', function() {
231-
expect(el).to.be.instanceOf(HTMLElement);
237+
expect(el).to.be.instanceOf(_HTMLElement);
232238
});
233239

234240
it('returns multiple elements if the template has multiple children', function() {

0 commit comments

Comments
 (0)