Skip to content

Commit

Permalink
Add tests for is-inert
Browse files Browse the repository at this point in the history
Fix global variable leakage around checking inertness setting
  • Loading branch information
dfreedm committed Feb 2, 2017
1 parent 9192514 commit e1561f6
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/lib/annotations/annotations.html
Expand Up @@ -10,6 +10,7 @@
<link rel="import" href="../case-map.html">

<script>
(function() {
/**
* Scans a template to produce an annotation list that that associates
* metadata culled from markup with tree locations
Expand Down Expand Up @@ -415,4 +416,6 @@

};

})();

</script>
3 changes: 2 additions & 1 deletion test/runner.html
Expand Up @@ -92,7 +92,8 @@
'unit/dom-bind-yield.html',
'unit/script-after-import-in-head.html',
'unit/globals.html',
'unit/lazy-register.html'
'unit/lazy-register.html',
'unit/element-inertness.html'
];

if (document.body.createShadowRoot) {
Expand Down
152 changes: 152 additions & 0 deletions test/unit/element-inertness.html
@@ -0,0 +1,152 @@
<!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
-->
<meta charset="utf-8">
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../../web-component-tester/browser.js"></script>
<script>Polymer = {enableInert: true}</script>
<link rel="import" href="../../polymer.html">

<dom-module id="x-inert">
<template>
<style>
:host {
display: block;
}
</style>
<div id="child">Live!</div>
</template>
<script>
HTMLImports.whenReady(function() {
Polymer({
is: 'x-inert'
});
});
</script>
</dom-module>

<test-fixture id="simple">
<template>
<x-inert is-inert></x-inert>
</template>
</test-fixture>

<dom-module id="x-complicated-child">
<script>
HTMLImports.whenReady(function() {
Polymer({
is: 'x-complicated-child',
properties: {
a: {
observer: 'aChanged'
},
c: {
observer: 'cChanged'
},
aRan: {
value: false
},
cRan: {
value: false
}
},
aChanged: function() {
this.aRan = true;
},
cChanged: function() {
this.cRan = true;
}
});
})
</script>
</dom-module>

<dom-module id="x-complicated-inert">
<template>
<x-complicated-child id="child" a="{{a}}" is-inert="{{b}}" c="{{c}}"></x-complicated-child>
</template>
<script>
HTMLImports.whenReady(function() {
Polymer({
is: 'x-complicated-inert',
properties: {
a: {value: true},
b: {value: true},
c: {value: true}
}
});
});
</script>
</dom-module>

<test-fixture id="databind-inert">
<template>
<x-complicated-inert></x-complicated-inert>
</template>
</test-fixture>

<dom-module id="x-complicated-not-inert">
<template>
<x-complicated-child id="child" a="{{a}}" is-inert="{{b}}" c="{{c}}"></x-complicated-child>
</template>
<script>
HTMLImports.whenReady(function() {
Polymer({
is: 'x-complicated-not-inert',
properties: {
a: {value: true},
b: {value: false},
c: {value: true}
}
});
});
</script>
</dom-module>

<test-fixture id="databind-not-inert">
<template>
<x-complicated-not-inert></x-complicated-not-inert>
</template>
</test-fixture>

<script>
suite('Element Inertness', function() {
suite('Inert', function() {
var el;
setup(function() {
el = fixture('simple');
});
test('does not stamp when inert', function() {
assert.equal(el.isInert, true);
assert.notOk(el.shadowRoot);
assert.notOk(el.$);
});
test('stamps when isInert is removed', function() {
el.isInert = false;
assert.ok(el.root);
assert.ok(el.$.child);
});
});
suite('Inertness and Databinding', function() {
test('binding to is-inert with true', function() {
var el = fixture('databind-inert');
assert.equal(el.$.child.isInert, true);
assert.equal(el.$.child.aRan, undefined);
assert.equal(el.$.child.cRan, undefined);
});
test('bindings to is-inert with false', function () {
var el = fixture('databind-not-inert');
assert.notOk(el.$.child.isInert);
assert.equal(el.$.child.aRan, true);
assert.equal(el.$.child.cRan, true);
})
})
});
</script>

0 comments on commit e1561f6

Please sign in to comment.