Files
polymer/test/unit/template-whitespace.html
2015-10-28 12:54:20 -07:00

177 lines
4.5 KiB
HTML

<!doctype html>
<!--
@license
Copyright (c) 2014 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>
<dom-module id="has-whitespace">
<template> <div>A</div> <div>B</div> </template>
<script>
HTMLImports.whenReady(function() {
Polymer({
is: 'has-whitespace'
});
});
</script>
</dom-module>
<dom-module id="no-whitespace">
<template strip-whitespace>
<div>A</div>
<div>A</div>
<div>B</div>
</template>
<script>
HTMLImports.whenReady(function() {
Polymer({
is: 'no-whitespace'
});
});
</script>
</dom-module>
<dom-module id="no-whitespace-style">
<template strip-whitespace>
<style>
:host {
display: block;
}
</style>
<div>A</div>
<div>B</div>
</template>
<script>
HTMLImports.whenReady(function() {
Polymer({
is: 'no-whitespace-style'
});
});
</script>
</dom-module>
<dom-module id="no-whitespace-nested">
<template strip-whitespace>
<div>
<div>A</div>
</div>
<div>
<div>B</div>
</div>
</template>
<script>
HTMLImports.whenReady(function() {
Polymer({
is: 'no-whitespace-nested'
});
});
</script>
</dom-module>
<dom-module id="no-whitespace-binding">
<template strip-whitespace>
<div id="text">{{text}}</div>
<div id="attr" attr$="{{attr}}">
<div>A</div>
</div>
<div>
<div>B</div>
</div>
<div id="compound"> {{a}} {{b}} </div>
</template>
<script>
HTMLImports.whenReady(function() {
Polymer({
properties: {
text: {value: 'text'},
attr: {value: 'attr'},
a: {value: 'a'},
b: {value: 'b'}
},
is: 'no-whitespace-binding'
});
});
</script>
</dom-module>
<script>
suite('polymer: template whitespace', function() {
test('template stamped with whitespace preserved', function() {
var el = document.createElement('has-whitespace');
assert.equal(Polymer.dom(el.root).childNodes.length, 5);
assert.equal(Polymer.dom(el.root).childNodes[0].nodeType, Node.TEXT_NODE);
});
test('template stamped without whitespace when strip-template is used', function() {
var el = document.createElement('no-whitespace');
document.body.appendChild(el);
assert.equal(Polymer.dom(el.root).childNodes.length, 3);
assert.equal(Polymer.dom(el.root).childNodes.length, Polymer.dom(el.root).children.length);
});
test('template including style stamped without whitespace when strip-template is used', function() {
var el = document.createElement('no-whitespace-style');
document.body.appendChild(el);
assert.equal(Polymer.dom(el.root).childNodes.length, 2);
assert.equal(Polymer.dom(el.root).childNodes.length, Polymer.dom(el.root).children.length);
});
test('template with nested content stamped without whitespace when strip-template is used', function() {
var el = document.createElement('no-whitespace-nested');
document.body.appendChild(el);
assert.equal(Polymer.dom(el.root).childNodes.length, 2);
assert.equal(Polymer.dom(el.root).childNodes.length, Polymer.dom(el.root).children.length);
assert.equal(Polymer.dom(el.root).childNodes[0].childNodes.length, Polymer.dom(el.root).childNodes[0].children.length);
assert.equal(Polymer.dom(el.root).childNodes[1].childNodes.length, Polymer.dom(el.root).childNodes[1].children.length);
});
test('template with nested content stamped without whitespace when strip-template is used', function() {
var el = document.createElement('no-whitespace-binding');
document.body.appendChild(el);
assert.equal(el.$.text.textContent, 'text');
assert.equal(el.$.attr.getAttribute('attr'), 'attr');
assert.equal(el.$.compound.textContent, ' a b ');
});
});
</script>
</body>
</html>