upvote
i view this as the strength of dynamic language like JS or Ruby rather than a weakness: look at all the busywork a language like Java would otherwise inflict on us that we’re able to avoid. it takes a single syntactic lint rule to enforce type safe use of these module mock APIs (enforce `testlib.mock<typeof import(P)>(P, …)`), and only about 100 lines of one time setup to add mock helpers in vitest to mock a specific export rather than the whole module. There are also lint rules that prevent pretty much all scoping problem misuse of hoisted apis like testlib.mock.

Your course should mention these techniques! Without them tests are unsound!

We do some dependency injection of our framework-level service objects like ServerApiService or RouterService or RecordCacheService (usually with a subclass of the actual implementation) but it hardly needs to be ubiquitous or typical for product developer code.

reply