11const { getElementType} = require ( '../../lib/utils/get-element-type' )
2+ const mocha = require ( 'mocha' )
3+ const describe = mocha . describe
4+ const it = mocha . it
25const expect = require ( 'chai' ) . expect
36
47function mockJSXAttribute ( prop , propValue ) {
@@ -15,7 +18,7 @@ function mockJSXAttribute(prop, propValue) {
1518 }
1619}
1720
18- function mockJSXOpeningElement ( tagName , attributes = [ ] , children = [ ] ) {
21+ function mockJSXOpeningElement ( tagName , attributes = [ ] ) {
1922 return {
2023 type : 'JSXOpeningElement' ,
2124 name : {
@@ -37,12 +40,12 @@ function mockSetting(componentSetting = {}) {
3740}
3841
3942describe ( 'getElementType' , function ( ) {
40- it ( 'gets element type' , function ( ) {
43+ it ( 'returns raw element type' , function ( ) {
4144 const node = mockJSXOpeningElement ( 'a' )
4245 expect ( getElementType ( { } , node ) ) . to . equal ( 'a' )
4346 } )
4447
45- it ( 'gets element type from default' , function ( ) {
48+ it ( 'returns element type from default if set ' , function ( ) {
4649 const node = mockJSXOpeningElement ( 'Link' , [ mockJSXAttribute ( 'as' , 'summary' ) ] )
4750 const setting = mockSetting ( {
4851 Link : {
@@ -52,7 +55,7 @@ describe('getElementType', function () {
5255 expect ( getElementType ( setting , node ) ) . to . equal ( 'button' )
5356 } )
5457
55- it ( 'gets element type from matching props setting' , function ( ) {
58+ it ( 'returns element type from matching props setting if set ' , function ( ) {
5659 const setting = mockSetting ( {
5760 Link : {
5861 default : 'a' ,
@@ -61,17 +64,12 @@ describe('getElementType', function () {
6164 }
6265 }
6366 } )
64- const node_1 = mockJSXOpeningElement ( 'Link' )
65- expect ( getElementType ( setting , node_1 ) ) . to . equal ( 'a' )
6667
67- const node_2 = mockJSXOpeningElement ( 'Link' , [ mockJSXAttribute ( 'as' , 'p' ) ] )
68- expect ( getElementType ( setting , node_2 ) ) . to . equal ( 'a' )
69-
70- const node_3 = mockJSXOpeningElement ( 'Link' , [ mockJSXAttribute ( 'as' , 'summary' ) ] )
71- expect ( getElementType ( setting , node_3 ) ) . to . equal ( 'summary' )
68+ const node = mockJSXOpeningElement ( 'Link' , [ mockJSXAttribute ( 'as' , 'summary' ) ] )
69+ expect ( getElementType ( setting , node ) ) . to . equal ( 'summary' )
7270 } )
7371
74- it ( 'uses original type if no default or matching prop setting' , function ( ) {
72+ it ( 'returns raw type if no default or matching prop setting' , function ( ) {
7573 const setting = mockSetting ( {
7674 Link : {
7775 props : {
@@ -95,7 +93,7 @@ describe('getElementType', function () {
9593 expect ( getElementType ( setting , node ) ) . to . equal ( 'a' )
9694 } )
9795
98- it ( 'falls back to original type if no default and prop does not match props setting' , function ( ) {
96+ it ( 'returns raw type if prop does not match props setting and no default type ' , function ( ) {
9997 const setting = mockSetting ( {
10098 Link : {
10199 props : {
0 commit comments