refactor(test): heavily simplify the context
helper
#404
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
NOTE: this is built on top of #397 as that also uses thecontext
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