In the mocks vs. no mocks debate, I’ve seen a complete ignoring of nuance which I think causes confusion; it sure confuses me at least. Examples include “you don’t need mocks, only stubs” or “test behavior, not implementation”.
(more…)Author: JesterXL
-
4 Things I’ve Learned From 6 Months of PR’s in a Large Angular Codebase
I’ve learned 4 things this past 6 months doing peer reviews on many teams’ code in a large Angular code base.
- Pure Functions are not an easy sell
- Avoiding Dependencies in code is not obvious
- Anti-Mock crowd unfortunately is more nuanced
- Acceptance Test Ops continue to be challenging
-
Six Alternatives to Using any in TypeScript
There are a few options, and strategies. We’ve listed from easiest to most thorough.
- Use any, then ask for help.
- Use unknown
- Use a Record with a string key and whatever value, like
Record<string, any>
. - Use
IDontKnowYet
as an aliased type or interface. - For a multitude of types, use an anonymous Union, like
string | number
. If you still don’t know, usestring | number | any
since we’ll knowany
is the outlier. - Use a Pick or Partial of an existing type you may already have nearby.
-
RxJS Observables That Can’t Fail
A habit I made in JavaScript, and later TypeScript, was to have Promises never fail, and instead return a Result type. This ensured async code worked like sync code, and didn’t randomly break the application. If someone decided to use async/await syntax, they could forget a try/catch and be “ok”. I only use that syntax in unit tests where you’d want things to explode sooner.
I’ve attempted recently to apply the same style to RxJS, and sadly it’s not working out. The first problem is that has the same contract as AWS Lambda: You can either get a return value, or an Exception if something went wrong. This allows AWS to support just about any programming language because almost all return values, and almost all have ways of making exceptions, intentionally, but most not.
(more…)