4 ms·
> 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 singl
by uwu 10y ago
> 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 10y agoHi, 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.