-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
test_addon-links_v3.x.x.js
106 lines (88 loc) · 2.19 KB
/
test_addon-links_v3.x.x.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// @flow
import { describe, it } from 'flow-typed-test';
import React from 'react';
import { linkTo, hrefTo } from '@storybook/addon-links';
import LinkTo from '@storybook/addon-links/react';
const Button = (props: {
onClick: (SyntheticMouseEvent<HTMLButtonElement>) => void,
...
}) => (
<button type="button" {...props}>
Click me
</button>
);
const Select = (props: {
onChange: (SyntheticInputEvent<HTMLSelectElement>) => void,
...
}) => (
<select {...props}>
<option>First</option>
<option>Second</option>
</select>
);
describe('The `linkTo` function', () => {
it('should accept string arguments', () => {
linkTo('');
linkTo('', '');
});
it('should accept callback agruments', () => {
linkTo(() => '', () => '');
linkTo('', evt => evt.currentTarget.value);
});
it('should returns an event handler', () => {
<button onClick={linkTo('', '')} />;
<Button onClick={linkTo('', '')} />;
<select onChange={linkTo('', e => e.currentTarget.value)}>
<option>First</option>
<option>Second</option>
</select>;
<Select onChange={linkTo('', e => e.currentTarget.value)} />;
});
it('should error on invalid args', () => {
// $ExpectError
linkTo();
// $ExpectError
linkTo({});
// $ExpectError
linkTo(true, true);
});
});
describe('The `hrefTo` function', () => {
it('should accept string arguments', () => {
hrefTo('', '');
});
it('should error on invalid args', () => {
// $ExpectError
hrefTo();
// $ExpectError
hrefTo({});
// $ExpectError
hrefTo(true, true);
});
it('returns a Promised string', () => {
hrefTo('', '').then(result => (result: string));
});
it('should error on invalid Promise result', () => {
// $ExpectError
hrefTo('', '').then(result => (result: boolean));
});
});
describe('The `LinkTo` component', () => {
it('should accept valid properties', () => {
<LinkTo
kind=""
story=""
target="_blank"
title=""
style={{ color: 'tomato' }}
>
Test
</LinkTo>;
});
it('should error on invalid properties', () => {
// $ExpectError
<LinkTo kind={123} story={true}>
Test
</LinkTo>;
});
});