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.
Updates
exposeMocks
(see: test/src/mock/helpers.ts)Advice
The following is a bit of advice which could help tremendously in getting the project wrapped up. Forgive me if you already know any of it. The hope is to leave you with some useful help to bring it home successfully and quickly!
1. Turn
strict
on intsconfig.json
Fair warning. It's going to frustrate you. But, if you bring your code up to spec, you'll eliminate a huge quantity of bugs that you wouldn't have found otherwise. It will also teach you TS fundamentals in a way that nothing else really can.
Similar to how failing tests will help you find issues, this will do the same!
2. Look up "Type Coercion" and "Truthy / Falsy" values for JavaScript
This one isn't too major, but it can help to simplify syntax and will be very beneficial in understanding how and why JS does the things it does.
For a live example, I noticed the following in the code:
Checking length is the sort of thing you'd need to do in a language like Swift. JS offers some interesting shortcuts due to coercion.
In this example, you can simply use
!payload.slug
, asundefined
is falsy and an empty string''
is falsy. So either''
orundefined
will evalues to true with the unary not operator.Additionally, the reason
!payload.slug?.length
would work with an empty string as well is because 0 also evaluates to falsy.The side benefit is, if you understand type coercion, you're approaching "I know Kung-Fu" JS mastery level 😎
3. Look into Jest's
Mock
.This is going to be critical moving forward. I built the mock clients in a way that you can take advantage of using
Mock
, by getting calls, setting up return values, etc. ThemockData
attached to each is meant to be a sort of default return value.Ultimately, the goal was when you get code working, you will likely want to setup custom return values in many situations. It's built to do that.
A good place to start and see what's available is by checking the autocomplete for
mockBikeTagClient.mocks.getTags
, et al.From there you can look at clearing / resetting mocks, etc. in the Jest documentation, which will help you a lot.