If JavaScript event handlers are checked per unit

Here are a lot of questions about unit test event handlers in other languages, but I couldn't find a good answer when it comes to JavaScript. In particular, we are talking about a case like:

// inside a "view" class definition:
handleCheckboxClick: function() {
    this.relevantData.toggleSomeValue();
    return false;
}

// later on:
$('#someCheckbox').on('click', view.handleCheckboxClick);

It’s clear that there is logic ( this.relevantData.toggleSomeValue()) in the event handler , but at the same time, no other method will ever call this handler, so it doesn’t like unit testing and will catch some future error related to refactoring. And in any specific JavaScript code base there is a LOTO of these handlers, so there is a non-trivial amount of work to check them.

In addition, many JS stores (of course, ours) also have object-level tests performed with Selenium, which usually capture obvious user interface problems (for example, when an event handler breaks).

So, on the one hand, I get this “unit testing logic == good”, and I don’t want to shoot in the foot without testing a specific code if I pay for it later. On the other hand, this particular subset of code seems to have high cost and low value when it comes to unit testing. So my question for the SO community is, should unit test JS developers fulfill their event handling functions?

+4
source share
1

, :)

, , . , ; , , ( ). , .

- , :

  • , . "", . , !
  • . , . " , ", . , - ;)
  • . , /. , "" - - .

, , . , .

+4

Source: https://habr.com/ru/post/1569498/


All Articles