Coding is as much a matter of personal growth as it is of logic and control-flow. I keep patience, curiosity, & exuberance in the same toolbox as vim and git.
*Opinions posted are my own*
I didn't look too deeply into your code, it looks like you've solved most of the problems already. It did seem like you were having a bit of trouble with one of your unit tests, though.
Thanks for you promptly answer. Well, you removed the most relevant part of my test: el.shadowRoot.querySelector('#firstdiv2');. Basically, I want to check if there is a div with id firstdiv2 and it must fail since the correct id is firstdiv. Your suggestion will pass but, as fafr as I ccan see, you are just checking if the fixture works; you aren't checking anything from the webcomponent html.
Coding is as much a matter of personal growth as it is of logic and control-flow. I keep patience, curiosity, & exuberance in the same toolbox as vim and git.
*Opinions posted are my own*
if your goal is to test that the shadow root renders the way you expect, I suggest using the open-wc package semantic-dom-diff, which is built-in to open-wc's testing setup, like so:
import{expect,fixture}from`@open-wc/testing`;describe('skyscanner flight search',function(){it('should render the correct Shadow DOM',asyncfunction(){constel=awaitfixture(`<skyscanner-flight-search></skyscanner-flight-search>`);awaitwindow.customElements.whenDefined('skyscanner-flight-search')expect(el).shadowDom.to.equal(`
<!-- this dom string will be semantically compared to the real dom -->
<!-- comments will be stripped out -->
<!-- and you'll get a helpful diff as otuput if you use open-wc's testing setup -->
<div id="firstDiv"></div>
<input id="inputSessionKey"/>
`);});});
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hello,
I didn't look too deeply into your code, it looks like you've solved most of the problems already. It did seem like you were having a bit of trouble with one of your unit tests, though.
Try this:
Thanks for you promptly answer. Well, you removed the most relevant part of my test: el.shadowRoot.querySelector('#firstdiv2');. Basically, I want to check if there is a div with id firstdiv2 and it must fail since the correct id is firstdiv. Your suggestion will pass but, as fafr as I ccan see, you are just checking if the fixture works; you aren't checking anything from the webcomponent html.
Based on your suggestion, I found a solution:
import { html, fixture, expect } from '@open-wc/testing';
import '../src/skyscanner-flight-search/skyscanner-flight-search.js';
describe('skyscanner flight search', () => {
it('show div', async() => {
const el = await fixture(html
);<skyscanner-flight-search></skyscanner-flight-search>
await window.customElements.whenDefined('skyscanner-flight-search')
expect(el.shadowRoot.querySelector('#firstdiv')).to.exist;
});
What is your opinion about how I am testing? IN few words, it is based on Karma + Mocha and depending on fixture approaches.
if your goal is to test that the shadow root renders the way you expect, I suggest using the open-wc package
semantic-dom-diff
, which is built-in to open-wc's testing setup, like so: