
Fantastic Unit Tests in JavaScript with Mocks - musikele
https://michelenasti.com/2017/04/07/fantastic-unit-tests-in-javascript-with-mocks.html
======
uwu
> However, even if the db object is not reassignable, we can still modify its
> internals, as long they are declared as let and var. That’s why we will mock
> single functions and not the whole object.

this doesn't work for the awful practice encouraged by eslint (at least when i
last tried it) that consists of ignoring that there exists a keyword
specifically for declaring functions, and abusing constants with arrow
functions instead

sure, it prevents you from reassigning the function variable and using `this`
but aren't those things what you use a linter for?

~~~
musikele
Hi, I admit that finding the right balance between elegant mocks and effective
coding is difficult. If you want to mock objects, using rewire, means that you
should never use const for your internal modules. On the other side, one might
choose to apply some dependency injection and pass modules via the
"constructor" (let me pass the term). That's not good too. So, my default
choice is to use const for modules and real constants, and let for the rest.
This way I can elegantly test my code. For me, testing is more important than
respecting rules chosen by others.

