-
Notifications
You must be signed in to change notification settings - Fork 298
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
fix(clerk-react,nextjs): Type checking in vitest unit tests #4844
fix(clerk-react,nextjs): Type checking in vitest unit tests #4844
Conversation
🦋 Changeset detectedLatest commit: 7cfb605 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
if (!current.userId) { | ||
throw 'Invalid state'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just assert this is truthy
if (!current.userId) { | |
throw 'Invalid state'; | |
} | |
expect(current.userId).toBeTruthy(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did this in order to have typescript narrow down the type of current.has below and make not undefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear that's why this logic is here then. Why not just use optional chaining below
const result = current.has?.({ permission: 'test' });
|
||
const result = current.has({ permission: 'test' }); | ||
expect(result).toBe(false); | ||
expectTypeOf(result).toBeBoolean(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type assertion isn't really needed as you are already asserting that result is strictly false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted this expectTypeOf(result).toBeBoolean();
which performs a type check. I can simply revert tbh.
@panteliselef 👍🏼 This makes sense. I noticed a while back that we have some blind spots as far as type checks go so started looking at it here: #4778 |
I went with this route since we are using Mostly I wanted to ensure that any testing around types that previously was working with jest, continues to do so. On the long run I'm happy to change or keep it. |
@panteliselef I agree this is the right way to go 💯 , especially for those |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description
We need to opt in to typechecking in order to the type errors throw by
expect-type
to be caught and cause the tests to fail.Checklist
pnpm test
runs as expected.pnpm build
runs as expected.Type of change