-
Notifications
You must be signed in to change notification settings - Fork 934
Expand file tree
/
Copy pathdoclink.test.ts
More file actions
79 lines (69 loc) · 2.31 KB
/
doclink.test.ts
File metadata and controls
79 lines (69 loc) · 2.31 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import * as link from '../doclink';
const mockPlatform = jest.fn().mockReturnValue('darwin');
jest.mock('os', () => ({
platform: mockPlatform,
}));
describe('link', () => {
it('builds a link with the platform and os defined', () => {
mockPlatform.mockReturnValueOnce('darwin');
link.setPlatform('android');
const url = new URL(
link.docs('set-up-your-environment', 'inherit'),
).toString();
expect(url).toMatch(/os=macos/);
expect(url).toMatch(/platform=android/);
expect(url).toEqual(
expect.stringContaining(
'https://reactnative.dev/docs/set-up-your-environment',
),
);
// Handles a change of os
mockPlatform.mockReturnValueOnce('win32');
expect(link.docs('set-up-your-environment', 'inherit')).toMatch(
/os=windows/,
);
// Handles a change of platform
link.setPlatform('ios');
expect(link.docs('set-up-your-environment', 'inherit')).toMatch(
/platform=ios/,
);
// Handles cases where we don't need a platform
expect(link.blog('2019/11/18/react-native-doctor', 'none')).not.toMatch(
/platform=/,
);
});
it('preserves anchor-links', () => {
expect(link.docs('set-up-your-environment', 'inherit', 'ruby')).toMatch(
/#ruby/,
);
});
describe('overrides', () => {
afterAll(() => link.setVersion(null));
it.each([
[{hash: 'ruby'}, /#ruby/],
[{hash: 'ruby', os: 'linux'}, /os=linux/],
[{'extra stuff': 'here?ok'}, /extra\+stuff=here%3Fok/],
])("link.doc('set-up-your-environment, %o) -> %o", (param, re) => {
expect(link.docs('set-up-your-environment', 'none', param)).toMatch(re);
});
});
describe('enforces platform inheritance', () => {
it("asserts on not setting the platform for link.docs('foo', 'inherit')", () => {
link.setPlatform(null);
expect(() => {
link.docs('foobar', 'inherit');
}).toThrow(/link\.setPlatform/);
});
});
describe('versions', () => {
afterAll(() => link.setVersion(null));
it('supports linking to a specific version of React Native', () => {
link.setVersion('0.71');
expect(link.docs('set-up-your-environment', 'ios', 'ruby')).toEqual(
expect.stringContaining(
'https://reactnative.dev/docs/0.71/set-up-your-environment',
),
);
});
});
});