-
Notifications
You must be signed in to change notification settings - Fork 267
Expand file tree
/
Copy pathindex.test.tsx
More file actions
52 lines (47 loc) · 1.26 KB
/
index.test.tsx
File metadata and controls
52 lines (47 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import * as clickTracking from '#app/hooks/useClickTrackerHandler';
import { render } from '../react-testing-library-with-providers';
import Link from '.';
describe('Link', () => {
it.each([
{
type: 'html',
spaLink: false,
},
{
type: 'Next',
spaLink: true,
},
])(
'should render a valid anchor element for a $type type link',
({ spaLink }) => {
const href = '/forwarding_link';
const title = 'Some Title';
const { container } = render(
<Link href={href} spaLink={spaLink}>
{title}
</Link>,
);
const anchor = container.querySelector('a');
expect(anchor?.href).toBe(`http://localhost${href}`);
expect(anchor?.innerHTML).toBe(title);
},
);
it('should track clicks', () => {
const href = '/forwarding_link';
const title = 'Some Title';
const isSpaLink = true;
const sampleEventData = {
url: href,
block: {
componentName: title,
},
};
const clickTrackerSpy = jest.spyOn(clickTracking, 'default');
render(
<Link href={href} eventTrackingData={sampleEventData} spaLink={isSpaLink}>
{title}
</Link>,
);
expect(clickTrackerSpy).toHaveBeenCalledWith(sampleEventData, isSpaLink);
});
});