forked from 4Catalyzer/found
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Improve link API (4Catalyzer#241)
BREAKING CHANGE: Rename Component prop on <Link> to as BREAKING CHANGE: Remove childProps prop from <Link>
- Loading branch information
Showing
14 changed files
with
233 additions
and
72 deletions.
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
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
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
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
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,61 @@ | ||
jest.mock('warning'); | ||
|
||
import React from 'react'; | ||
import warning from 'warning'; | ||
|
||
import Link from '../src/Link'; | ||
import { mountWithRouter } from './helpers'; | ||
|
||
const CustomComponent = () => <div />; | ||
|
||
describe('<Link> warnings', () => { | ||
it('should warn on component prop', async () => { | ||
// The below will log a warning for an invalid prop. | ||
jest.spyOn(console, 'error').mockImplementation(() => {}); | ||
|
||
await mountWithRouter(<Link component={CustomComponent} to="/" />); | ||
|
||
expect(warning).toHaveBeenCalledWith( | ||
false, | ||
'Link to %s with `%s` prop `%s` has an element type that is not a component. The expected prop for the link component is `as`.', | ||
'"/"', | ||
'component', | ||
'CustomComponent', | ||
); | ||
}); | ||
|
||
it('should warn on Component prop', async () => { | ||
// The below will log a warning for an invalid prop. | ||
jest.spyOn(console, 'error').mockImplementation(() => {}); | ||
|
||
await mountWithRouter(<Link Component={CustomComponent} to="/" />); | ||
|
||
expect(warning).toHaveBeenCalledWith( | ||
false, | ||
'Link to %s with `%s` prop `%s` has an element type that is not a component. The expected prop for the link component is `as`.', | ||
'"/"', | ||
'Component', | ||
'CustomComponent', | ||
); | ||
}); | ||
|
||
it('should not warn when as prop is specified', async () => { | ||
await mountWithRouter( | ||
<Link | ||
as={CustomComponent} | ||
to="/" | ||
component={CustomComponent} | ||
// eslint-disable-next-line react/jsx-no-duplicate-props | ||
Component={CustomComponent} | ||
/>, | ||
); | ||
|
||
expect(warning).not.toHaveBeenCalledWith( | ||
false, | ||
'Link to %s with `%s` prop `%s` has an element type that is not a component. The expected prop for the link component is `as`.', | ||
expect.anything(), | ||
expect.anything(), | ||
expect.anything(), | ||
); | ||
}); | ||
}); |
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
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
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,24 @@ | ||
import { WithRouterProps } from 'found'; | ||
import withRouter from 'found/lib/withRouter'; | ||
import * as React from 'react'; | ||
|
||
interface Props extends WithRouterProps { | ||
foo?: boolean; | ||
} | ||
|
||
class ComponentWithRouter extends React.Component<Props> { | ||
render() { | ||
const { | ||
match: { location }, | ||
router, | ||
} = this.props; | ||
return ( | ||
<div> | ||
{location.pathname}, {router} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const ComponentWithRouterContainer = withRouter(ComponentWithRouter); | ||
export { ComponentWithRouterContainer as ComponentWithRouter }; |
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,16 @@ | ||
import * as React from 'react'; | ||
|
||
interface Props { | ||
href: string; | ||
active: boolean; | ||
onClick: (event: React.SyntheticEvent<any>) => void; | ||
children: React.ReactNode; | ||
} | ||
|
||
export function CustomLink({ href, active, onClick, children }: Props) { | ||
return ( | ||
<a href={href} className={active ? 'active' : ''} onClick={onClick}> | ||
{children} | ||
</a> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import * as React from 'react'; | ||
import { WithRouterComponent } from './WithRouterComponent'; | ||
|
||
const MainPage = () => ( | ||
<div> | ||
<WithRouterComponent /> | ||
</div> | ||
); | ||
export { MainPage }; | ||
import { ComponentWithRouter } from './ComponentWithRouter'; | ||
|
||
export function MainPage() { | ||
return ( | ||
<div> | ||
<ComponentWithRouter /> | ||
</div> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import * as React from 'react'; | ||
|
||
const WidgetsPage = () => <div />; | ||
export { WidgetsPage }; | ||
export function WidgetsPage() { | ||
return <div />; | ||
} |
Oops, something went wrong.