Skip to content

Commit

Permalink
fix: add renderItem test, fix renderItem teardown
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrik Kullman authored and JockeCK committed Jun 25, 2020
1 parent fc10bdf commit cb51ae6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cosmoz-data-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,11 @@ class CosmozDataNav extends hauntedPolymer('haunted', useDataNav)(mixinBehaviors

this.splice('_elements', 0, this._elements.length, this._createElement())
.forEach(element => {
this._removeInstance(element.__instance);
if (this.renderItem) {
element.removeChild(element.__instance);
} else {
this._removeInstance(element.__instance);
}
element.removeChild(element.__incomplete);
element.__instance = element.__incomplete = null;
});
Expand Down
29 changes: 29 additions & 0 deletions test/basic.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable max-lines */
import {
assert, fixture, html, oneEvent, waitUntil
} from '@open-wc/testing';
Expand Down Expand Up @@ -400,3 +401,31 @@ suite('renderQueue', () => {
});
});
});

suite('renderItem', () => {
let nav,
itemsRendered = 0;
const renderItem = (item, index) => {
itemsRendered += 1;
return html`
<cosmoz-data-nav-test-view class="fit layout vertical" item="${ item }" index="${ index }">
</cosmoz-data-nav-test-view>
`;
};

suiteSetup(async () => {
[, nav] = await Promise.all([
fixture(visibilityFixture),
setupFixture(html`
<cosmoz-data-nav .renderItem="${ renderItem }">
</cosmoz-data-nav>
`)
]);
});

test('renders items', async () => {
nav.items = [{ id: '0' }, { id: '1' }, { id: '2' }];
flushRenderQueue(nav);
assert.equal(itemsRendered, nav.items.map(nav.isIncompleteFn).filter(i => !i).length);
});
});

0 comments on commit cb51ae6

Please sign in to comment.