-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(clerk-react): Avoid error on
useRoutingOptions()
when path
pa…
…ssed from options (#2514)
- Loading branch information
Showing
4 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@clerk/clerk-react': patch | ||
--- | ||
|
||
Fixes error thrown for missing path & routing props when path was passed from context. | ||
This change affects components `<SignIn />`, `<SignUp />` from `@clerk/nextjs` and `@clerk/remix`. |
31 changes: 31 additions & 0 deletions
31
packages/react/src/hooks/__tests__/__snapshots__/useRoutingProps.test.tsx.snap
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`useRoutingProps() returns passed props and options for routing different than path 1`] = ` | ||
<body> | ||
<div> | ||
<div> | ||
{"routing":"virtual","prop1":"1","prop2":"2"} | ||
</div> | ||
</div> | ||
</body> | ||
`; | ||
|
||
exports[`useRoutingProps() returns passed props and options if path is passed from routing options 1`] = ` | ||
<body> | ||
<div> | ||
<div> | ||
{"path":"/aloha","prop1":"1","prop2":"2"} | ||
</div> | ||
</div> | ||
</body> | ||
`; | ||
|
||
exports[`useRoutingProps() returns path routing with passed props and options if path prop is passed 1`] = ` | ||
<body> | ||
<div> | ||
<div> | ||
{"path":"/aloha","prop1":"1","prop2":"2","routing":"path"} | ||
</div> | ||
</div> | ||
</body> | ||
`; |
74 changes: 74 additions & 0 deletions
74
packages/react/src/hooks/__tests__/useRoutingProps.test.tsx
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { render } from '@testing-library/react'; | ||
import React from 'react'; | ||
|
||
import { useRoutingProps } from '../useRoutingProps'; | ||
|
||
const originalError = console.error; | ||
|
||
describe('useRoutingProps()', () => { | ||
beforeAll(() => { | ||
console.error = jest.fn(); | ||
}); | ||
|
||
afterAll(() => { | ||
console.error = originalError; | ||
}); | ||
|
||
it('throws error without routing & path props', () => { | ||
const TestingComponent = props => { | ||
const options = useRoutingProps('TestingComponent', props); | ||
return <div>{JSON.stringify(options)}</div>; | ||
}; | ||
|
||
expect(() => { | ||
render(<TestingComponent />); | ||
}).toThrowError('<TestingComponent/> is missing a path prop to work with path based routing'); | ||
}); | ||
|
||
it('returns path routing with passed props and options if path prop is passed', () => { | ||
const TestingComponent = props => { | ||
const options = useRoutingProps('TestingComponent', props); | ||
return <div>{JSON.stringify(options)}</div>; | ||
}; | ||
|
||
const { baseElement } = render( | ||
<TestingComponent | ||
path='/aloha' | ||
prop1='1' | ||
prop2='2' | ||
/>, | ||
); | ||
expect(baseElement).toMatchSnapshot(); | ||
}); | ||
|
||
it('returns passed props and options for routing different than path', () => { | ||
const TestingComponent = props => { | ||
const options = useRoutingProps('TestingComponent', props); | ||
return <div>{JSON.stringify(options)}</div>; | ||
}; | ||
|
||
const { baseElement } = render( | ||
<TestingComponent | ||
routing='virtual' | ||
prop1='1' | ||
prop2='2' | ||
/>, | ||
); | ||
expect(baseElement).toMatchSnapshot(); | ||
}); | ||
|
||
it('returns passed props and options if path is passed from routing options', () => { | ||
const TestingComponent = props => { | ||
const options = useRoutingProps('TestingComponent', props, { path: '/aloha' }); | ||
return <div>{JSON.stringify(options)}</div>; | ||
}; | ||
|
||
const { baseElement } = render( | ||
<TestingComponent | ||
prop1='1' | ||
prop2='2' | ||
/>, | ||
); | ||
expect(baseElement).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains 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