Whenever you ship something to be used by others, you take on a responsibility to deliver safe and stable code. One way to address this is by testi...
For further actions, you may consider blocking this person and/or reporting abuse
Thank you for the time to writing this awesome tutorial!
Working through it has tremendously improved my understanding of the bits and pieces that make up testing in JS in general and for web components in particular.
I have been fiddling around with the "updates are asynchronous" problem, and found what looks like a solution: The updateComplete promise.
Using this promise, waiting for the updates to finish seems straight forward:
The tests pass using this construct, but -- as you already pointed out -- passing tests doesn't mean the tests actually work correctly. So maybe that's introducing more trouble down the line or hiding something, that I am unaware of, but still I have to ask: Is there a particular reason, you decided not to use
updateComplete
?thxxxx ❤️
you are correct - using
updateComplete
will make the test pass. And in tests I useupdateComplete
a lot :) even thefixture
itself relies on it 💪However, setting properties is usually not an async action. So you would need to know that it's async and then you would need to know how to await this async-ness.
For logging it could be ok to stay async, unless you are actually logging timings 🙈
However other things
really would feel strange if they only work if you await an rendering update?
the "calculation" of a fullName should not depend on the updates of the dom.
I hope this makes it a little more clear 🤗
you can also read more in the original issue: github.com/Polymer/lit-element/iss...
Ah yes, I see what you mean now. Thanks for the added details.
I even had a look at the issue before I wrote my comment, but I just didn't get it in its entirety 🙈
Don't we want to install dependencies first before running
npm test
?Are you sure you selected to add "Testing" and do scaffolding for it?
You will need to hit "Space" and not "Enter" as it's a multi selection - it's a little confusing - we still want to improve that 🙈
Like you, I guess most people will quickly figure out that you have to 'cd' into it, ie :
$ cd a11y-input
That step is missing.
I wonder if something changed in the generator between the time it was written and now :/
Not sure it is possible to follow through this tutorial at the present time.
Even after copying the dependencies and scripts from the Github project, and running
npm run test
this is what I get:This pretty much blocks me from the beginning, which is a bummer since this blog post seem to be a very thorough one.
I recognize the post is almost 3 years old and I congratulate OP for such work. At the same time I ask if by any chance there's a workaround, a newer version of the same content, etc.
Happy holidays!
I find it odd that you select 'No':
✔ Do you want to install dependencies? › No
and yet:
npm run test
which complains about karma missing.
Did the 'test' 'script' used to do an 'npm install' or something. Why wouldn't you get the generator to install everything?
Hrm, I think things have changed too much, since even the 'npm run test' doesn't work as described.
@passle on the polymer @open-wc slack channel suggests just using the files as they are made by the generator.
I an not able to set up this.. Npm run test giving error.. Saying no test specified.. Content of blog is good.. But i think some setup file or steps are missing..
hey, thx for letting me know :) the setup changed a little as the @open-wc generator evolved. I updated the appropriate part.
If it doesn't work out for you the easier would be to clone github.com/daKmoR/testing-workflow... and play around there - it has a working setup.
HI Another query is what is the snapshot check use case , if somebody have updated then our changes are lost right? so what will be the right use case for testing the web components via snapshot
Snapshots are useful especially for components which very big dom trees - in these cases it's pretty painful to maintain 2 "versions" of the same dom (e.g. the actual dom and the dom you compare to in your test).
With snapshots you will be get an error whenever the html structure changed - what comes next depends:
The important part here is that updating the snapshots is faster/simpler than manually adjusting a "dom string" (hence for doms with less then ~5-10 nodes it's probably impractical)
Thanks for replying . Can you have all types of testing methods like event , loading of data like that.The link that you have shared consist of high level testing.
This is a setup of a Testing System you can test whatever is possible to test with JavaScript. Writing tests first usually results in a better API as you will need to make sure that your code is testable and all the needed information is publicly accessible.
For events just add an event listener and then expect if it was called the correct amount of times and with the expected parameters. Sinon can help in this case.
For data loading it really depends on your solution - sometimes it makes sense to check which properties end up on the web component and you there could be a "loading complete event" you await before testing. Or the data management has nothing to do with the component as it just get's passed in all the information via a global state management system.
So in short you should be able to test almost everything not only web components related :)
Thank you Thomas. One thing i would like to hear from you is webcomponenets using angular vs lit-elements. what is your opinion about this. if you are not aware about this , can you give me some references regarding the same.
Hi Thomas,
i made one dropdown component and i want to test on changing on value one event should dispatch. but dispatch event method is on selection change method. how i will call selection change method, by firing event (if yes how?)or by taking the id on select tag (which is inside dropdown component)and firing event.
So what this lib actually does? Run some dev server and a headless chrome against it? Can I connect to the server manually?
how i can import other package such as jQuery, axios in Open Web Components