-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
/
Copy pathlink.test.js
49 lines (41 loc) · 1.22 KB
/
link.test.js
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
// Copyright (c) Meta Platforms, Inc. and affiliates.. All Rights Reserved.
'use strict';
import renderer from 'react-test-renderer';
import Link from '../Link';
it('renders correctly', () => {
const tree = renderer
.create(<Link page="http://www.facebook.com">Facebook</Link>)
.toJSON();
expect(tree).toMatchSnapshot();
});
it('renders as an anchor when no page is set', () => {
const tree = renderer.create(<Link>Facebook</Link>).toJSON();
expect(tree).toMatchSnapshot();
});
it('properly escapes quotes', () => {
const tree = renderer
.create(<Link>{"\"Facebook\" \\'is \\ 'awesome'"}</Link>)
.toJSON();
expect(tree).toMatchSnapshot();
});
it('changes the class when hovered', () => {
const component = renderer.create(
<Link page="http://www.facebook.com">Facebook</Link>,
);
let tree = component.toJSON();
expect(tree).toMatchSnapshot();
// manually trigger the callback
renderer.act(() => {
tree.props.onMouseEnter();
});
// re-rendering
tree = component.toJSON();
expect(tree).toMatchSnapshot();
// manually trigger the callback
renderer.act(() => {
tree.props.onMouseLeave();
});
// re-rendering
tree = component.toJSON();
expect(tree).toMatchSnapshot();
});