padcom / vue-dropdown

0 stars 0 forks source link

nice tests #2

Open AleksejDix opened 2 years ago

AleksejDix commented 2 years ago

I really like how you write test? How would you deal with dom updates and testing network layer?

https://github.com/padcom/vue-dropdown/blob/10816c06bd6a73b3a8753ae474a6880b2e9b07e7/lib/components/SimpleSelect.test.js#L118

padcom commented 2 years ago

It depends on the case, but as a general rule I prefer to have the "thing" (function, class, object) that is responsible for making those external calls extracted outside of the component and then, without using any kind of mocking framework (which I am not a fan of) provide the right test implementation.

Also, I am of the opinion that one should test the component's public API. So if the component should react to different things, like addition or removal of elements, I'd check if the relevant elements are present. That all goes into the wrapper class, which then, in the case of a bigger use case like a form or some other organism, won't make me write those selectors again and again making maintenance of those tests a nightmare.

I'm not sure if that's what you're after here, but that's basically what I'd do.