adding unit test to forOwnerOnly #794#795
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
| authProviderId: 'auth0|123456789012345678901234' | ||
| } | ||
| // Create a mock component to be used with forOwnerOnly | ||
| const MockComponent: React.FC<WithOwnerProfile> = () => <div>Mock Component</div> |
Contributor
There was a problem hiding this comment.
consider:
const MockComponent = (unusedProps: WithOwnerProfile) => <div>Mock Component</div>
| }) | ||
|
|
||
| it('should render the component if isAuthorized is true', async () => { | ||
| (usePermissions as jest.Mock).mockReturnValue({ isAuthorized: true }) |
Contributor
There was a problem hiding this comment.
// jest.Mock(usePermission)
not sure the actual constructor here so pseudocode above. the pseudocode would in theory should have the correct prototype, previously you are just adding the type which does nothing. The only reason it is working is because of some jest global environment magic.
actuallyyun
pushed a commit
that referenced
this pull request
May 7, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request adds unit tests for the forOwnerOnly higher order function, which is used to restrict access to certain components or functions to a specific owner. The tests verify that the function behaves as expected and that it correctly restricts access to components based on if isAuthorized returns
truefrom the mocked usePermission hook.