Why unit test JavaScript?

Not the first read that unit tests are cool. However, I don't see how they can help in real projects.
Now I have the feeling that I write a lot of tests, spend a lot of time, but nothing will.
Or that you need to provide everything, but if provided then why actually test?
I will give examples.

Instead of one event has occurred, the mass of events, for example, a user stumbles quickly and contend items, plus they have some answers ajax.
So there have been many calls to different functions are mixed. I was not able to provide. As unit-test will help me if I didn't know about these events?

- The font in the browser etrangeres later than usual, and I have not provided that its dimensions will be zero at the time of activation functions.
How could I not knowing this and assuming her to write the test? Is every line of JS code need not to trust?

- The application runs in a complex way, referring to Google fonts, to "own" the server, creating multiple copies...
As unit-test will be able to run the whole process and keep track of all the errors, taking into account all situations?
For example in a certain moment at a certain answer Google test will show the error? In the complex process of launching the application and not just on the individual light functions.
July 8th 19 at 11:18
5 answers
July 8th 19 at 11:20
Head to think, and to understand unit test that doesn't "start the whole process" by definition, if the whole process, it is a functional test, in some cases quite functional testing.
July 8th 19 at 11:22
What you describe does not apply to unit tests. This is all the integration (functional) testing, or just a glitch as in the case of 0 width.

Unit tests check the operation of the module. By writing tests you records the contract module in relation to other parts of the system. If in the course of refactoring or revision of the contract suddenly changed. Tests you about it just say. Ie they don't need to check what's working right now, they need to make sure that everything is working as intended then.
July 8th 19 at 11:24
Unit tests in the front is most useful for "Foundation" application. For example, you write some libo that is responsible for logic and data processing. It will be very useful to test to continue to focus on the interface and to be a little bit sure that if there is a bug, its causes lie deep.
The same functionality (events, DOM changes) should be tested only in order to further the expansion of application, it is easy to verify that basic functionality is not broken. Naturally, all options for user interaction in all environments to test are not real. Only base.
July 8th 19 at 11:26
Option testing for the lazy https://habrahabr.ru/post/216805/
July 8th 19 at 11:28
Not the first read that unit tests are cool. However, I don't see how they can help in real projects.
Now I have the feeling that I write a lot of tests, spend a lot of time, but nothing will.
Or that you need to provide everything, but if provided then why actually test?

Corny then you don't have to manually launch a browser and then 5 options where each still a range of versions, which all should work as it should. That's what automated testing was invented in the first place, i.e. it allows to test very much for a very small period of time (comparison with real hands).

Additional cool things:
- If something worked fine and then stopped - you learn about it, and find a reason for this.
- If the test worked well, you can dismiss the risks which you know, because you describe them in the test, and hammer head risk that you forgot to include. For example to give the security test result, and they will check that you have not provided neither in the tests nor in the project.

Find more questions by tags JavaScript