This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support document.registerElement
Closes #18
- Loading branch information
Showing
2 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* check that document.registerElement(name, { prototype: proto }); | ||
* is properly patched | ||
*/ | ||
|
||
'use strict'; | ||
|
||
describe('document.registerElement', function () { | ||
if (!'registerElement' in document) { | ||
console.log('WARNING: skipping document.registerElement test (missing this API)'); | ||
return; | ||
} | ||
|
||
var flag, hasParent; | ||
|
||
// register a custom element for each callback | ||
var callbacks = [ | ||
'created', | ||
'attached', | ||
'detached', | ||
'attributeChanged' | ||
]; | ||
|
||
function flagAndCheckZone() { | ||
flag = true; | ||
hasParent = !!window.zone.parent; | ||
} | ||
|
||
var customElements = callbacks.map(function (callbackName) { | ||
var fullCallbackName = callbackName + 'Callback'; | ||
var proto = Object.create(HTMLElement.prototype); | ||
proto[fullCallbackName] = flagAndCheckZone; | ||
return document.registerElement('x-' + callbackName.toLowerCase(), { | ||
prototype: proto | ||
}); | ||
}); | ||
|
||
|
||
beforeEach(function () { | ||
flag = false; | ||
hasParent = false; | ||
}); | ||
|
||
|
||
it('should work with createdCallback', function () { | ||
runs(function () { | ||
var elt = document.createElement('x-created'); | ||
}); | ||
|
||
waitsFor(function() { | ||
return flag; | ||
}, 'createdCallback to fire', 100); | ||
|
||
runs(function() { | ||
expect(hasParent).toBe(true); | ||
}); | ||
}); | ||
|
||
|
||
it('should work with attachedCallback', function () { | ||
runs(function () { | ||
var elt = document.createElement('x-attached'); | ||
document.body.appendChild(elt); | ||
document.body.removeChild(elt); | ||
}); | ||
|
||
waitsFor(function() { | ||
return flag; | ||
}, 'attachedCallback to fire', 100); | ||
|
||
runs(function() { | ||
expect(hasParent).toBe(true); | ||
}); | ||
}); | ||
|
||
|
||
it('should work with detachedCallback', function () { | ||
runs(function () { | ||
var elt = document.createElement('x-detached'); | ||
document.body.appendChild(elt); | ||
document.body.removeChild(elt); | ||
}); | ||
|
||
waitsFor(function() { | ||
return flag; | ||
}, 'detachedCallback to fire', 100); | ||
|
||
runs(function() { | ||
expect(hasParent).toBe(true); | ||
}); | ||
}); | ||
|
||
|
||
it('should work with attributeChanged', function () { | ||
runs(function () { | ||
var elt = document.createElement('x-attributechanged'); | ||
elt.id = 'bar'; | ||
}); | ||
|
||
waitsFor(function() { | ||
return flag; | ||
}, 'attributeChanged to fire', 100); | ||
|
||
runs(function() { | ||
expect(hasParent).toBe(true); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters