Skip to content

Commit

Permalink
Fix tests in non-Chrome browsers
Browse files Browse the repository at this point in the history
The customElements.get function was undefined until
the polyfill resolved the HTMLImports.
Instead of waiting for the imports to resolve and
modifying the prototype, it was easier to extract
a function that does the logic, as the prototype
was not properly propagated in non-Chrome browsers
  • Loading branch information
TimvdLippe committed Aug 1, 2017
1 parent 0596465 commit 5a54c32
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions test/unit/dom-repeat.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
<script src="../../../web-component-tester/browser.js"></script>
<link rel="import" href="../../polymer.html">
<link rel="import" href="dom-repeat-elements.html">
<script>
if (document.location.search.indexOf('restamp') >= 0) {
customElements.get('dom-repeat').prototype.restamp = true;
}
</script>
<style>
/* makes painting faster when testing on IOS simulator */
x-repeat-chunked {
Expand Down Expand Up @@ -151,6 +146,14 @@ <h4>x-repeat-chunked</h4>
stamped[38] .. 3-3-3
*/

function setupFixture(fixtureName) {
var el = fixture(fixtureName);
if (document.location.search.indexOf('restamp') >= 0) {
el.restamp = true;
}
return el;
}

function arrayDelete(el, path, item) {
var array = el.get(path);
var idx = array.indexOf(item);
Expand All @@ -174,7 +177,7 @@ <h4>x-repeat-chunked</h4>
let configured;

setup(function() {
configured = fixture('configured');
configured = setupFixture('configured');
Polymer.flush();
});

Expand Down Expand Up @@ -650,7 +653,7 @@ <h4>x-repeat-chunked</h4>
let unconfigured;

setup(function() {
unconfigured = fixture('unconfigured');
unconfigured = setupFixture('unconfigured');
unconfigured.items = window.getData();
unconfigured.$.el1.prop = 'outer';
unconfigured.$.el1.item = {prop: 'outerItem'};
Expand Down Expand Up @@ -783,7 +786,7 @@ <h4>x-repeat-chunked</h4>
let unconfigured;

setup(function() {
unconfigured = fixture('unconfigured');
unconfigured = setupFixture('unconfigured');
unconfigured.items = window.getData();
Polymer.flush();
});
Expand Down Expand Up @@ -871,7 +874,7 @@ <h4>x-repeat-chunked</h4>
let unconfigured;

setup(function() {
unconfigured = fixture('unconfigured');
unconfigured = setupFixture('unconfigured');
unconfigured.items = window.getData();
Polymer.flush();
unconfigured.$.el1.domUpdateHandlerCount = 0;
Expand Down Expand Up @@ -1124,7 +1127,7 @@ <h4>x-repeat-chunked</h4>
let unconfigured;

setup(function() {
unconfigured = fixture('unconfigured');
unconfigured = setupFixture('unconfigured');
unconfigured.items = window.getData();
unconfigured.$.el1.$.repeater.filter = function(o) {
return o.prop.indexOf('2') < 0;
Expand Down Expand Up @@ -1334,7 +1337,7 @@ <h4>x-repeat-chunked</h4>
let unconfigured;

setup(function() {
unconfigured = fixture('unconfigured');
unconfigured = setupFixture('unconfigured');
unconfigured.items = window.getData();
unconfigured.$.el1.$.repeater.sort = function(a, b) {
return b.prop == a.prop ? 0 : b.prop < a.prop ? -1 : 1;
Expand Down Expand Up @@ -1543,7 +1546,7 @@ <h4>x-repeat-chunked</h4>
var unconfigured

setup(function() {
unconfigured = fixture('unconfigured');
unconfigured = setupFixture('unconfigured');
unconfigured.items = window.getData();
unconfigured.$.el1.$.repeater.sort = function(a, b) {
return b.prop == a.prop ? 0 : b.prop < a.prop ? -1 : 1;
Expand Down Expand Up @@ -1742,7 +1745,7 @@ <h4>x-repeat-chunked</h4>
let unconfigured;

setup(function() {
unconfigured = fixture('unconfigured-mutable');
unconfigured = setupFixture('unconfigured-mutable');
unconfigured.items = window.getData();
Polymer.flush();
});
Expand Down Expand Up @@ -2042,7 +2045,7 @@ <h4>x-repeat-chunked</h4>
let unconfigured;

setup(function() {
unconfigured = fixture('unconfigured-mutable');
unconfigured = setupFixture('unconfigured-mutable');
unconfigured.items = window.getData();
unconfigured.$.el1.$.repeater.filter = function(o) {
return o.prop.indexOf('2') < 0;
Expand Down Expand Up @@ -2259,7 +2262,7 @@ <h4>x-repeat-chunked</h4>
let unconfigured;

setup(function() {
unconfigured = fixture('unconfigured-mutable');
unconfigured = setupFixture('unconfigured-mutable');
unconfigured.items = window.getData();
unconfigured.$.el1.$.repeater.sort = function(a, b) {
return b.prop == a.prop ? 0 : b.prop < a.prop ? -1 : 1;
Expand Down Expand Up @@ -2475,7 +2478,7 @@ <h4>x-repeat-chunked</h4>
let unconfigured;

setup(function() {
unconfigured = fixture('unconfigured-mutable');
unconfigured = setupFixture('unconfigured-mutable');
unconfigured.items = window.getData();
unconfigured.$.el1.$.repeater.sort = function(a, b) {
return b.prop == a.prop ? 0 : b.prop < a.prop ? -1 : 1;
Expand Down Expand Up @@ -2681,7 +2684,7 @@ <h4>x-repeat-chunked</h4>
let primitive;

setup(function() {
primitive = fixture('primitive');
primitive = setupFixture('primitive');
Polymer.flush();
});

Expand Down Expand Up @@ -3227,7 +3230,7 @@ <h4>x-repeat-chunked</h4>
let primitive;

setup(function() {
primitive = fixture('primitive');
primitive = setupFixture('primitive');
Polymer.flush();
});

Expand Down Expand Up @@ -3284,7 +3287,7 @@ <h4>x-repeat-chunked</h4>
});

test('structured values - initial stamping', function() {
let unconfigured = fixture('unconfigured');
let unconfigured = setupFixture('unconfigured');
unconfigured.items = window.getData();
Polymer.flush();
var stamped1 = unconfigured.$.el1.root.querySelectorAll('*:not(template):not(dom-repeat)');
Expand All @@ -3294,7 +3297,7 @@ <h4>x-repeat-chunked</h4>
});

test('structured values - change from inside', function() {
let unconfigured = fixture('unconfigured');
let unconfigured = setupFixture('unconfigured');
unconfigured.items = window.getData();
Polymer.flush();
var stamped1 = unconfigured.$.el1.root.querySelectorAll('*:not(template):not(dom-repeat)');
Expand All @@ -3311,7 +3314,7 @@ <h4>x-repeat-chunked</h4>
});

test('structured values - sorted', function() {
let unconfigured = fixture('unconfigured');
let unconfigured = setupFixture('unconfigured');
unconfigured.items = window.getData();
Polymer.flush();
unconfigured.$.el1.$.repeater.sort = function(a, b) {
Expand Down Expand Up @@ -3347,7 +3350,7 @@ <h4>x-repeat-chunked</h4>
836, 564, 721, 540, 372,
244, 145, 525, 958, 595,
207, 103, 602, 769, 190];
let primitive = fixture('primitive');
let primitive = setupFixture('primitive');
primitive.items = items;
setTimeout(function() {
var stamped1 = primitive.$.container1.querySelectorAll('*:not(template):not(dom-repeat)');
Expand All @@ -3374,7 +3377,7 @@ <h4>x-repeat-chunked</h4>
let unconfigured;

setup(function() {
unconfigured = fixture('unconfigured');
unconfigured = setupFixture('unconfigured');
unconfigured.items = window.getData();
Polymer.flush();
});
Expand Down Expand Up @@ -3483,7 +3486,7 @@ <h4>x-repeat-chunked</h4>
});

test('renderedItemCount', function() {
let primitive = fixture('primitive');
let primitive = setupFixture('primitive');
Polymer.flush();
var repeater1 = primitive.$.repeater1;
primitive.items = [ 'a', 'b', 'c', 'd', 'e' ];
Expand All @@ -3503,7 +3506,7 @@ <h4>x-repeat-chunked</h4>

test('_showHideChildren', function() {
// Initially all showing
let primitive = fixture('primitive');
let primitive = setupFixture('primitive');
Polymer.flush();
var stamped1 = primitive.$.container1.querySelectorAll('*:not(template):not(dom-repeat)');
assert.equal(getComputedStyle(stamped1[0]).display, 'block');
Expand Down Expand Up @@ -4046,7 +4049,7 @@ <h4>x-repeat-chunked</h4>
suite('misc', function() {

test('large splice', function(done) {
let primitiveLarge = fixture('primitiveLarge');
let primitiveLarge = setupFixture('primitiveLarge');
Polymer.flush();
primitiveLarge.splice('items', 0, 10);
setTimeout(function() {
Expand All @@ -4062,7 +4065,7 @@ <h4>x-repeat-chunked</h4>
if (!window.ShadyDOM) {
this.skip();
}
let simple = fixture('simple');
let simple = setupFixture('simple');
Polymer.flush();
var removed;
// Confirm initial scoping
Expand Down Expand Up @@ -4093,7 +4096,7 @@ <h4>x-repeat-chunked</h4>
});

test('paths update on observed properties', function() {
let simple = fixture('simple');
let simple = setupFixture('simple');
Polymer.flush();
//debugger;
var stamped = simple.root.querySelectorAll('*:not(template):not(dom-repeat)');
Expand Down Expand Up @@ -4123,7 +4126,7 @@ <h4>x-repeat-chunked</h4>
suite('dom-change composed', function() {

test('dom-change event composed, bubbles outside dom-if scope', function() {
var el = fixture('simple');
var el = setupFixture('simple');
var domChangeFired = 0;
el.addEventListener('dom-change', function() {
domChangeFired++;
Expand Down

0 comments on commit 5a54c32

Please sign in to comment.