I am very new to lit-element and unit testing and am not sure if the question is even framed correctly. Please correct me if I am wrong anywhere.
So, I have 1 lit component created such that it fetches the json from the uri
<abc infoJsonLink="../data/data.json"></abc>
data.json
[
{"id":1, "name":"one", "img":"one.jpg"},
{"id":1, "name":"two", "img":"two.jpg"},
...]
Within abc's render() method, we loop through the json data and create a array with html markup corresponding to each item, itemsMarkupList
*0* <div "item-data"><span>one</span><img src="one.jpg"/></div>
*1* <div "item-data"><span>two</span><img src="two.jpg"/></div>
*2* ...
Each one of these markups, has to be rendered in a bootstrap carousel. https://mdbootstrap.com/snippets/jquery/ascensus/135508
For this we have created another component, <carousel-helper>
, which has the code to accept an array of markups and render it as a carousel using bootstrap libraries.
Below is the render()
method of <abc>
component
render(){...
let ch = document.createElement("carousel-helper");
ch.itemsMarkupList = this.itemsMarkupList;
return html`... <div class="parent_wrapper"> ${ch} </div>`;
}
This whole renders perfectly when I npm run
it.
But when I am writing the test cases for this, the shadowroot of child elements seems to be not rendering.
it("test1", async () => {
const el = /** @type {Abc} */ (await fixture(
html`<abc infoJsonLink="/data/data.json"></abc>
`));
await el.loadJsonData();
/*statement 1*/
console.log(el.shadowRoot.querySelector("carousel-helper"));
/*statement 2*/
console.log(el.shadowRoot.querySelector("carousel-helper").
shadowRoot.querySelectorAll(".item-data"));
});
statement-1 works and returns <carousel-helper></carousel-helper>
statement-2 return and empty array, NodeList {}
Can anyone tell me what I need to do to get a filled array from statement-2?