feat(client): Migrate <Link> to ts (#42467)

* rename

* migrate

* fix: remove duplicate

* fix: linting

Co-authored-by: Parth Parth <thecodingaviator@users.noreply.github.com>
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
Parth Parth
2021-06-25 20:49:21 +05:30
committed by Mrugesh Mohapatra
parent 8c7cc2e532
commit f15a55e2b4
2 changed files with 11 additions and 7 deletions

View File

@ -1,25 +1,27 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import React from 'react';
import renderer, { ReactTestRendererJSON } from 'react-test-renderer';
import { create } from 'react-test-renderer';
import Link from './link';
describe('<Link />', () => {
const externalLink = renderer
.create(<Link external={true} to='/home' />)
.toJSON() as ReactTestRendererJSON;
const gatsbyLink = renderer
.create(<Link to='/home' />)
.toJSON() as ReactTestRendererJSON;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const externalLink = create(<Link external={true} to='/home' />).toJSON();
const gatsbyLink = create(<Link to='/home' />).toJSON();
it('renders to the DOM', () => {
expect(gatsbyLink).toBeTruthy();
});
it('sets target for external links', () => {
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
expect(externalLink.props.target).toEqual('_blank');
});
it('does not specify target in gatsbyLink', () => {
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
expect(gatsbyLink.props.target).toBeFalsy();
});
});

View File

@ -6,6 +6,8 @@ interface LinkProps {
external?: boolean;
sameTab?: boolean;
to: string;
// TODO: figure out what these actually should be
other?: any[];
}
const Link = ({