Hacker News new | past | comments | ask | show | jobs | submit login

Keeping mocks and tests in general up to date with reality can be tricky for sure. One thing that works very well for me, since you're using Typescript, is to use the ReturnType [0] generic to make sure the mock matches up to the actual implementation.

[0] https://www.typescriptlang.org/docs/handbook/utility-types.h...




I think this suggestion highlights why I'm not a fan of the module-level mocking approach. It puts the onus on the developer to ensure that type checks are present where they wouldn't otherwise be. On larger teams, I've found that stuff like that is too easy to forget about or choose not to do.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: