Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests #146

Open
wants to merge 4 commits into
base: tests
Choose a base branch
from
Open

Tests #146

wants to merge 4 commits into from

Conversation

nonara
Copy link
Contributor

@nonara nonara commented Jan 10, 2022

Updates

  • Fixed and simplified client mocks with new utility function exposeMocks (see: test/src/mock/helpers.ts)
  • Corrected some issues in current tests

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 in tsconfig.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:

if (!payload.slug?.length) { /* ... */ }

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, as undefined is falsy and an empty string '' is falsy. So either '' or undefined 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. The mockData 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant