-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Expand file tree
/
Copy pathlink.test.js
More file actions
42 lines (33 loc) · 1.26 KB
/
link.test.js
File metadata and controls
42 lines (33 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
// Copyright (c) Meta Platforms, Inc. and affiliates.. All Rights Reserved.
'use strict';
import Link from '../Link';
import {cleanup, render} from '@testing-library/react';
import {screen} from '@testing-library/dom';
import userEvent from '@testing-library/user-event';
afterEach(() => cleanup());
it('renders correctly', () => {
const {container} = render(
<Link page="http://www.facebook.com">Facebook</Link>,
);
expect(container.firstChild).toMatchSnapshot();
});
it('renders as an anchor when no page is set', () => {
const {container} = render(<Link>Facebook</Link>);
expect(container.firstChild).toMatchSnapshot();
});
it('properly escapes quotes', () => {
const {container} = render(<Link>{"\"Facebook\" \\'is \\ 'awesome'"}</Link>);
expect(container.firstChild).toMatchSnapshot();
});
it('changes the class when hovered', async () => {
const {container, rerender} = render(
<Link page="http://www.facebook.com">Facebook</Link>,
);
expect(container.firstChild).toMatchSnapshot();
// hover the link
userEvent.hover(container.firstChild);
expect(await screen.findByLabelText('hovered')).toMatchSnapshot();
// unhover the link
userEvent.unhover(container.firstChild);
expect(await screen.findByLabelText('normal')).toMatchSnapshot();
});