@@ -141,48 +141,57 @@ describe('<Tabs />', () => {
141141 test ( 'should render all tabs if forceRenderTabPanel is true' , ( ) => {
142142 expectToMatchSnapshot ( createTabs ( { forceRenderTabPanel : true } ) ) ;
143143 } ) ;
144+ } ) ;
144145
145- test ( 'should not clone non tabs element' , ( ) => {
146- class Demo extends React . Component {
147- render ( ) {
148- const arbitrary1 = < div ref = "arbitrary1" > One</ div > ; // eslint-disable-line react/no-string-refs
149- const arbitrary2 = < span ref = "arbitrary2" > Two</ span > ; // eslint-disable-line react/no-string-refs
150- const arbitrary3 = < small ref = "arbitrary3" > Three</ small > ; // eslint-disable-line react/no-string-refs
151-
152- return (
153- < Tabs >
154- < TabList >
155- { arbitrary1 }
156- < Tab > Foo</ Tab >
157- { arbitrary2 }
158- < Tab > Bar</ Tab >
159- { arbitrary3 }
160- </ TabList >
146+ describe ( 'validation' , ( ) => {
147+ test ( 'should result with warning when tabs/panels are imbalanced' , ( ) => {
148+ const oldConsoleError = console . error ; // eslint-disable-line no-console
149+ console . error = ( ) => { } ; // eslint-disable-line no-console
150+ const wrapper = shallow (
151+ < Tabs >
152+ < TabList >
153+ < Tab > Foo</ Tab >
154+ </ TabList >
155+ </ Tabs > ,
156+ ) ;
157+ console . error = oldConsoleError ; // eslint-disable-line no-console
161158
162- < TabPanel > Hello Baz</ TabPanel >
163- < TabPanel > Hello Faz</ TabPanel >
164- </ Tabs >
165- ) ;
166- }
167- }
159+ const result = Tabs . propTypes . children ( wrapper . props ( ) , 'children' , 'Tabs' ) ;
160+ expect ( result instanceof Error ) . toBe ( true ) ;
161+ } ) ;
168162
169- const wrapper = mount ( < Demo /> ) ;
163+ test ( 'should result with warning when tab outside of tablist' , ( ) => {
164+ const oldConsoleError = console . error ; // eslint-disable-line no-console
165+ console . error = ( ) => { } ; // eslint-disable-line no-console
166+ const wrapper = shallow (
167+ < Tabs >
168+ < TabList >
169+ < Tab > Foo</ Tab >
170+ </ TabList >
171+ < Tab > Foo</ Tab >
172+ < TabPanel />
173+ < TabPanel />
174+ </ Tabs > ,
175+ ) ;
176+ console . error = oldConsoleError ; // eslint-disable-line no-console
170177
171- expect ( wrapper . ref ( 'arbitrary1' ) . text ( ) ) . toBe ( 'One' ) ;
172- expect ( wrapper . ref ( 'arbitrary2' ) . text ( ) ) . toBe ( 'Two' ) ;
173- expect ( wrapper . ref ( 'arbitrary3' ) . text ( ) ) . toBe ( 'Three' ) ;
178+ const result = Tabs . propTypes . children ( wrapper . props ( ) , 'children' , 'Tabs' ) ;
179+ expect ( result instanceof Error ) . toBe ( true ) ;
174180 } ) ;
175- } ) ;
176181
177- describe ( 'validation' , ( ) => {
178- test ( 'should result with warning when tabs/panels are imbalanced' , ( ) => {
182+ test ( 'should result with warning when multiple tablist components exist' , ( ) => {
179183 const oldConsoleError = console . error ; // eslint-disable-line no-console
180184 console . error = ( ) => { } ; // eslint-disable-line no-console
181185 const wrapper = shallow (
182186 < Tabs >
183187 < TabList >
184188 < Tab > Foo</ Tab >
185189 </ TabList >
190+ < TabList >
191+ < Tab > Foo</ Tab >
192+ </ TabList >
193+ < TabPanel />
194+ < TabPanel />
186195 </ Tabs > ,
187196 ) ;
188197 console . error = oldConsoleError ; // eslint-disable-line no-console
@@ -341,6 +350,27 @@ describe('<Tabs />', () => {
341350 assertTabSelected ( wrapper , 0 ) ;
342351 assertTabSelected ( innerTabs , 1 ) ;
343352 } ) ;
353+
354+ test ( 'should allow other DOM nodes' , ( ) => {
355+ expectToMatchSnapshot (
356+ < Tabs >
357+ < div id = "tabs-nav-wrapper" >
358+ < button > Left</ button >
359+ < div className = "tabs-container" >
360+ < TabList >
361+ < Tab />
362+ < Tab />
363+ </ TabList >
364+ </ div >
365+ < button > Right</ button >
366+ </ div >
367+ < div className = "tab-panels" >
368+ < TabPanel />
369+ < TabPanel />
370+ </ div >
371+ </ Tabs > ,
372+ ) ;
373+ } ) ;
344374 } ) ;
345375
346376 test ( 'should pass through custom properties' , ( ) => {
0 commit comments