But there is an important concern here. We are testing the business logic through the user-interface. That is a badidea.
It doesn’t make sense that we need a Browser with JQuery and all the DOM stuff to test that a variable is incremented (sigh…). We want to be able to test the counting logic in isolation.
But right now, it is embedded in the widget code. The first thing we need to do is separate those responsibilities.
Notice how all the counting details are now in the Counter and the CounterWidget receives the counter as a parameter.
As a consequence, we need to change the code that was creating the CounterWidget to this:
This way we can now test and use the Counter without anything related to the CounterWidget.
And to test the CounterWidget in isolation we can inject test doubles in that parameter.