-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Tests in components #1255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
When it comes to components themselves, the only assertions I generally care to make are about the shape of the data being passed in to it. Something like React's Related: #880 |
@TehShrike Components lend themselves most easily to unit tests; that's the most logical scope, i.e., test the thing itself. "Unit test" definition here would be a little squishy, but it means it mostly knows about its own implementation details, and nothing outside the scope of the component. This may sound contradictory, but I also agree mostly with this idea: https://twitter.com/rauchg/status/807626710350839808 That is, don't write too many unit tests. But write enough for the most important I/O of the component, so in that sense, I agree with your point about data. But there might be other considerations. Just the same, a larger set of integration or E2E tests might be worth considering. Before we throw it out entirely, I think it's worth doing a little bikeshedding. I haven't had time to fully think through this, and arguably, this is something Sapper is more suited to instead of Svelte alone, but I want to give it some time to simmer. One idea is to simply provide connection points, sort of like an API, for components to communicate test behaviors and I/O to. Like I said, I really haven't had time to think this through, but maybe something like:
I really actually don't like the above because it's not loosely coupled, but I'm trying to actually bring something to the discussion. I'd love to hear other ideas. Including Sapper like implementation, which can be taken up somewhere in a Sapper ticket if it becomes a thing to talk about over there. 🤓 |
Oh, by the way, in terms of tests inside the component, that one does seem to have some more obvious approaches. A potential example:
Again haven't thought through fully correct permutations. What exactly needs testing? How does one differentiate between computed, method, and helper testing? How do we keep this testing framework agnostic? Etc. |
I write a good number of unit tests, but they're almost always for business logic/complex data transformations, and I put that logic in their own files outside of the component. Besides development mode assertions that my app provided components the data that they expected, the only things I can think of that I would want to assert about a component would be:
For the vast majority of the unit tests I write, the assertions themselves don't take up much space. Most of the lines in the tests are dedicated to defining the set of inputs and expected outputs of the function. I wouldn't want to clutter up my component with this test data. I would get a ton of value from first-class PropTypes-like functionality, though. It's a great way to document component data shapes, and it catches annoying bugs early during development. (random aside about that rauchg tweet: people have completely different ideas about the difference between integration/unit tests https://twitter.com/TehShrike/status/880510235328356354 ) |
* update adapter-vercel * bump * try this
Just a placeholder for now on this idea: https://gitter.im/sveltejs/svelte?at=5aae6e8ae4d1c6360412d107
Will return to this soon.
The text was updated successfully, but these errors were encountered: