~NOTE: this is built on top of #397 as that also uses the context helper. It may also merge conflict with #396 if that is merged. As such, I've marked this PR as "Draft" until those PRs are merged (or otherwise closed).~
Rebased on top, fixed merge conflicts, and marked as ready for review.
Summary
Significantly simplify the context helper used in the unit tests with more forceful type-casting and directly using Jest mocks. This makes all usage of context significantly easier and less hacky, as can be seen in the changed tests here.
Follow-up to #321 / #135
Details
since we're type-casting it anyway, we can heavily simplify this and remove the stubs entirely
they're actually unused in the unit tests, so we don't need them at all
besides the type-checking, which we force with a cast anyway
the as unknown as is bad practice, and probably why I didn't use it initially (plus other typing issues), but it's much simpler this way and reflects the intent better -- just making it type-check with the few properties we use
we can also use Jest mocks directly instead of the hacky contextualLogger and passing data in
makeContext now creates the mocks, so we just need to check against context.error etc
this is much more familiar as it's what we use in the source and follows idiomatic Jest
rewrite all the checks to test against the mocks instead
I thought this felt too complicated / verbose before, but I had left this as is from brekk's initial test structure
now that I understand all the tests and test intent much better, I could rewrite this to be a good bit simpler
make the toBeFalsy() checks more precise by checking that the mock wasn't called
it returns void anyway, so toBeFalsy()always returns true; it's not much of a test
checking that the low verbosity level didn't trigger the mock to be called actually checks the test's intent
~NOTE: this is built on top of #397 as that also uses the
context
helper. It may also merge conflict with #396 if that is merged. As such, I've marked this PR as "Draft" until those PRs are merged (or otherwise closed).~ Rebased on top, fixed merge conflicts, and marked as ready for review.Summary
Significantly simplify the
context
helper used in the unit tests with more forceful type-casting and directly using Jest mocks. This makes all usage ofcontext
significantly easier and less hacky, as can be seen in the changed tests here.Details
since we're type-casting it anyway, we can heavily simplify this and remove the stubs entirely
as unknown as
is bad practice, and probably why I didn't use it initially (plus other typing issues), but it's much simpler this way and reflects the intent better -- just making it type-check with the few properties we usewe can also use Jest mocks directly instead of the hacky
contextualLogger
and passingdata
inmakeContext
now creates the mocks, so we just need to check againstcontext.error
etcmake the
toBeFalsy()
checks more precise by checking that the mock wasn't calledvoid
anyway, sotoBeFalsy()
always returns true; it's not much of a test