concept handleAddItem in category javascript

This is an excerpt from Manning's book Testing JavaScript Applications.
In your
domController.jsfile, create a function namedhandleAddItem. This function will receive aneventas its first argument, retrieve the submitted values, calladdItemto update the inventory, and thenupdateItemListto update the DOM.
Because this test directly invokes
handleAddItem, it doesn’t care about whether it’s attached to theformas a listener for thesubmitevent. If you try, for example, removing frommain.jsthe call toaddEventListener, this test will continue to pass. Again, you’ve found another case in which your application won’t work, but in which your tests will pass.Figure 6.4. The test for
handleAddIteminvokes it directly, causing it to update the document.![]()
Constructing events manually, as you’ve just done, can be useful to iterate quickly, and test your listeners in isolation as you build them. But, when it comes to creating reliable guarantees, this technique is inadequate. This unit test only covers the
handleAddItemfunction itself and, therefore, can’t guarantee that the application will work when users trigger real events.