You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`"Docusaurus error: Bad <Tabs> child <div>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop."`,
@@ -30,10 +49,12 @@ describe('Tabs', () => {
30
49
it('rejects bad Tabs defaultValue',()=>{
31
50
expect(()=>{
32
51
renderer.create(
33
-
<TabsdefaultValue="bad">
34
-
<TabItemvalue="v1">Tab 1</TabItem>
35
-
<TabItemvalue="v2">Tab 2</TabItem>
36
-
</Tabs>,
52
+
<TestProviders>
53
+
<TabsdefaultValue="bad">
54
+
<TabItemvalue="v1">Tab 1</TabItem>
55
+
<TabItemvalue="v2">Tab 2</TabItem>
56
+
</Tabs>
57
+
</TestProviders>,
37
58
);
38
59
}).toThrowErrorMatchingInlineSnapshot(
39
60
`"Docusaurus error: The <Tabs> has a defaultValue "bad" but none of its children has the corresponding value. Available values are: v1, v2. If you intend to show no default tab, use defaultValue={null} instead."`,
@@ -42,14 +63,16 @@ describe('Tabs', () => {
42
63
it('rejects duplicate values',()=>{
43
64
expect(()=>{
44
65
renderer.create(
45
-
<Tabs>
46
-
<TabItemvalue="v1">Tab 1</TabItem>
47
-
<TabItemvalue="v2">Tab 2</TabItem>
48
-
<TabItemvalue="v3">Tab 3</TabItem>
49
-
<TabItemvalue="v4">Tab 4</TabItem>
50
-
<TabItemvalue="v1">Tab 5</TabItem>
51
-
<TabItemvalue="v2">Tab 6</TabItem>
52
-
</Tabs>,
66
+
<TestProviders>
67
+
<Tabs>
68
+
<TabItemvalue="v1">Tab 1</TabItem>
69
+
<TabItemvalue="v2">Tab 2</TabItem>
70
+
<TabItemvalue="v3">Tab 3</TabItem>
71
+
<TabItemvalue="v4">Tab 4</TabItem>
72
+
<TabItemvalue="v1">Tab 5</TabItem>
73
+
<TabItemvalue="v2">Tab 6</TabItem>
74
+
</Tabs>
75
+
</TestProviders>,
53
76
);
54
77
}).toThrowErrorMatchingInlineSnapshot(
55
78
`"Docusaurus error: Duplicate values "v1, v2" found in <Tabs>. Every value needs to be unique."`,
@@ -58,54 +81,52 @@ describe('Tabs', () => {
58
81
it('accepts valid Tabs config',()=>{
59
82
expect(()=>{
60
83
renderer.create(
61
-
<ScrollControllerProvider>
62
-
<TabGroupChoiceProvider>
63
-
<Tabs>
64
-
<TabItemvalue="v1">Tab 1</TabItem>
65
-
<TabItemvalue="v2">Tab 2</TabItem>
66
-
</Tabs>
67
-
<Tabs>
68
-
<TabItemvalue="v1">Tab 1</TabItem>
69
-
<TabItemvalue="v2"default>
70
-
Tab 2
71
-
</TabItem>
72
-
</Tabs>
73
-
<TabsdefaultValue="v1">
74
-
<TabItemvalue="v1"label="V1">
75
-
Tab 1
76
-
</TabItem>
77
-
<TabItemvalue="v2"label="V2">
78
-
Tab 2
79
-
</TabItem>
80
-
</Tabs>
81
-
<Tabs
82
-
defaultValue="v1"
83
-
values={[
84
-
{value: 'v1',label: 'V1'},
85
-
{value: 'v2',label: 'V2'},
86
-
]}>
87
-
<TabItemvalue="v1">Tab 1</TabItem>
88
-
<TabItemvalue="v2">Tab 2</TabItem>
89
-
</Tabs>
90
-
<Tabs
91
-
defaultValue={null}
92
-
values={[
93
-
{value: 'v1',label: 'V1'},
94
-
{value: 'v2',label: 'V2'},
95
-
]}>
96
-
<TabItemvalue="v1">Tab 1</TabItem>
97
-
<TabItemvalue="v2">Tab 2</TabItem>
98
-
</Tabs>
99
-
<TabsdefaultValue={null}>
100
-
<TabItemvalue="v1"label="V1">
101
-
Tab 1
102
-
</TabItem>
103
-
<TabItemvalue="v2"label="V2">
104
-
Tab 2
105
-
</TabItem>
106
-
</Tabs>
107
-
</TabGroupChoiceProvider>
108
-
</ScrollControllerProvider>,
84
+
<TestProviders>
85
+
<Tabs>
86
+
<TabItemvalue="v1">Tab 1</TabItem>
87
+
<TabItemvalue="v2">Tab 2</TabItem>
88
+
</Tabs>
89
+
<Tabs>
90
+
<TabItemvalue="v1">Tab 1</TabItem>
91
+
<TabItemvalue="v2"default>
92
+
Tab 2
93
+
</TabItem>
94
+
</Tabs>
95
+
<TabsdefaultValue="v1">
96
+
<TabItemvalue="v1"label="V1">
97
+
Tab 1
98
+
</TabItem>
99
+
<TabItemvalue="v2"label="V2">
100
+
Tab 2
101
+
</TabItem>
102
+
</Tabs>
103
+
<Tabs
104
+
defaultValue="v1"
105
+
values={[
106
+
{value: 'v1',label: 'V1'},
107
+
{value: 'v2',label: 'V2'},
108
+
]}>
109
+
<TabItemvalue="v1">Tab 1</TabItem>
110
+
<TabItemvalue="v2">Tab 2</TabItem>
111
+
</Tabs>
112
+
<Tabs
113
+
defaultValue={null}
114
+
values={[
115
+
{value: 'v1',label: 'V1'},
116
+
{value: 'v2',label: 'V2'},
117
+
]}>
118
+
<TabItemvalue="v1">Tab 1</TabItem>
119
+
<TabItemvalue="v2">Tab 2</TabItem>
120
+
</Tabs>
121
+
<TabsdefaultValue={null}>
122
+
<TabItemvalue="v1"label="V1">
123
+
Tab 1
124
+
</TabItem>
125
+
<TabItemvalue="v2"label="V2">
126
+
Tab 2
127
+
</TabItem>
128
+
</Tabs>
129
+
</TestProviders>,
109
130
);
110
131
}).not.toThrow();// TODO Better Jest infrastructure to mock the Layout
111
132
});
@@ -114,22 +135,60 @@ describe('Tabs', () => {
114
135
expect(()=>{
115
136
consttabs=['Apple','Banana','Carrot'];
116
137
renderer.create(
117
-
<ScrollControllerProvider>
118
-
<TabGroupChoiceProvider>
119
-
<Tabs
120
-
// @ts-expect-error: for an edge-case that we didn't write types for
// @ts-expect-error: for an edge-case that we didn't write types for
143
+
defaultValue={0}>
144
+
{tabs.map((t,idx)=>(
122
145
// @ts-expect-error: for an edge-case that we didn't write types for
123
-
defaultValue={0}>
124
-
{tabs.map((t,idx)=>(
125
-
// @ts-expect-error: for an edge-case that we didn't write types for
126
-
<TabItemkey={idx}value={idx}>
127
-
{t}
128
-
</TabItem>
129
-
))}
130
-
</Tabs>
131
-
</TabGroupChoiceProvider>
132
-
</ScrollControllerProvider>,
146
+
<TabItemkey={idx}value={idx}>
147
+
{t}
148
+
</TabItem>
149
+
))}
150
+
</Tabs>
151
+
</TestProviders>,
152
+
);
153
+
}).not.toThrow();
154
+
});
155
+
it('rejects if querystring is true, but groupId falsy',()=>{
156
+
expect(()=>{
157
+
renderer.create(
158
+
<TestProviders>
159
+
<TabsqueryString>
160
+
<TabItemvalue="val1">Val1</TabItem>
161
+
<TabItemvalue="val2">Val2</TabItem>
162
+
</Tabs>
163
+
</TestProviders>,
164
+
);
165
+
}).toThrow(
166
+
'Docusaurus error: The <Tabs> component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".',
167
+
);
168
+
});
169
+
170
+
it('accept querystring=true when groupId is defined',()=>{
171
+
expect(()=>{
172
+
renderer.create(
173
+
<TestProviders>
174
+
<TabsqueryStringgroupId="my-group-id">
175
+
<TabItemvalue="val1">Val1</TabItem>
176
+
<TabItemvalue="val2">Val2</TabItem>
177
+
</Tabs>
178
+
</TestProviders>,
179
+
);
180
+
}).not.toThrow();
181
+
});
182
+
183
+
it('accept querystring as string, but groupId falsy',()=>{
0 commit comments