This repository is an example repository about refactoring a piece of plain JS into a structured and testable system of files and components.
The initial
folder contains the file that is then refactored.
The step_0
folder contains a simple split of the file into logical blocks.
The step_1
folder contains a "pseudo OOP" implementation of the blocks. It's structured, but it isn't testable almost at all as the constructors of the methods contain side effects.
The step_2_func
folder contains a functional implementation of the same page with tests and properly structured functional modules. Testing this is pain. Because of the way NodeJS exposes the contents of the module, even the exposed function aren't that easily mocked and spied. Therefore, testing is possible, but to a very limited extent or with a lot of tests only related additional code.
The step_2_oop
folder contains a object-oriented implementation of the same page with tests and properly structured class modules. Tests are also included. In this case the methods are easily mockable and testable. ALL of them. Therefore, this option seems to be preferable if you want to get a nice test coverage.
https://docs.google.com/presentation/d/1F2amkdfm-jUkxFNGVW16vpRgXi_ZPTT3xjTihc4Mplo/edit?usp=sharing