-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests Add a `Polymer.html = Polymer.html` line to `polymer.html` and `polymer-element.html` for modulizer exporting in Polymer 3.
- Loading branch information
Showing
7 changed files
with
128 additions
and
4 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
File renamed without changes.
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
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
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
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
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,114 @@ | ||
<!doctype html> | ||
<!-- | ||
@license | ||
Copyright (c) 2017 The Polymer Project Authors. All rights reserved. | ||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt | ||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | ||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt | ||
Code distributed by Google as part of the polymer project is also | ||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt | ||
--> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script> | ||
<script src="../../../web-component-tester/browser.js"></script> | ||
<link rel="import" href="../../polymer.html"> | ||
</head> | ||
<body> | ||
<script> | ||
suite('html function', function() { | ||
test('html makes an HTML template', function() { | ||
let t = Polymer.html``; | ||
assert.instanceOf(t, HTMLTemplateElement); | ||
}); | ||
test('template output has elements', function() { | ||
let t = Polymer.html`<div><span></span></div><!-- hi -->`; | ||
assert(t.content.querySelector('div')); | ||
assert(t.content.querySelector('span')); | ||
assert.instanceOf(t.content.lastChild, Comment); | ||
}); | ||
test('escaping works as expected', function() { | ||
let t = Polymer.html`<span>\f\o\o</span>`; | ||
assert.equal(t.innerHTML, '<span>\\f\\o\\o</span>'); | ||
}); | ||
test('variables work', function() { | ||
let a = 3; | ||
let b = 'foo'; | ||
let t = Polymer.html`<div>${a} ${b}</div>`; | ||
let inst = document.createElement('div'); | ||
inst.appendChild(t.content.cloneNode(true)); | ||
assert.equal(inst.textContent, `${a} ${b}`); | ||
}); | ||
test('template variables only include the template contents', function() { | ||
let t1 = Polymer.html`<div></div>`; | ||
let t2 = Polymer.html`<span>${t1}</span>`; | ||
assert.equal(t2.innerHTML, '<span><div></div></span>'); | ||
}); | ||
}); | ||
suite('Polymer + html fn', function() { | ||
suiteSetup(function() { | ||
|
||
class HtmlFn extends Polymer.Element { | ||
static get is() {return 'html-fn';} | ||
static get template() { | ||
return Polymer.html` | ||
<style> | ||
:host { | ||
display: block; | ||
} | ||
</style> | ||
<div id="child"> | ||
[[databoundProperty]] | ||
</div> | ||
`; | ||
} | ||
static get properties() { | ||
return { | ||
databoundProperty: String | ||
}; | ||
} | ||
ready() { | ||
super.ready(); | ||
this.databoundProperty = 'first'; | ||
} | ||
} | ||
|
||
customElements.define(HtmlFn.is, HtmlFn); | ||
|
||
class HtmlFnSub extends HtmlFn { | ||
static get is() {return 'html-fn-sub';} | ||
static get template() { | ||
return Polymer.html` | ||
<div id="super"> | ||
${super.template} | ||
</div> | ||
`; | ||
} | ||
ready() { | ||
super.ready(); | ||
this.databoundProperty = 'second'; | ||
} | ||
} | ||
|
||
customElements.define(HtmlFnSub.is, HtmlFnSub); | ||
}); | ||
|
||
test('Polymer elements can use html fn', function () { | ||
let el = document.createElement('html-fn'); | ||
document.body.appendChild(el); | ||
assert(el.shadowRoot); | ||
assert.equal(el.$.child.textContent.trim(), 'first'); | ||
}); | ||
|
||
test('subclass elements can embed the superclass template', function() { | ||
let el = document.createElement('html-fn-sub'); | ||
document.body.appendChild(el); | ||
assert(el.$.super); | ||
assert(el.$.child); | ||
assert.equal(el.$.child.textContent.trim(), 'second'); | ||
}); | ||
}); | ||
</script> | ||
</body> | ||
</html> |