forked from sindresorhus/ink-link
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
65 lines (55 loc) · 1.33 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import {serial as test} from 'ava';
import React from 'react';
import {Color} from 'ink';
import {render} from 'ink-testing-library';
import clearModule from 'clear-module';
test.beforeEach(() => {
clearModule.all();
});
test.afterEach(() => {
delete process.env.FORCE_HYPERLINK;
});
test('render', t => {
process.env.FORCE_HYPERLINK = 1;
const Link = require('.');
const {lastFrame} = render(
<Link url="https://sindresorhus.com">
My{' '}<Color green>Website</Color>
</Link>
);
console.log(lastFrame());
t.snapshot(lastFrame());
});
test('render fallback', t => {
process.env.FORCE_HYPERLINK = 0;
const Link = require('.');
const {lastFrame} = render(
<Link url="https://sindresorhus.com">
My Website
</Link>
);
console.log(lastFrame());
t.snapshot(lastFrame());
});
test('exclude fallback if disabled', t => {
process.env.FORCE_HYPERLINK = 0;
const Link = require('.');
const {lastFrame} = render(
<Link url="https://sindresorhus.com" fallback={false}>
My Website
</Link>
);
console.log(lastFrame());
t.snapshot(lastFrame());
});
test('include fallback if explicitly enabled', t => {
process.env.FORCE_HYPERLINK = 0;
const Link = require('.');
const {lastFrame} = render(
<Link fallback url="https://sindresorhus.com">
My Website
</Link>
);
console.log(lastFrame());
t.snapshot(lastFrame());
});