1
- import { createElement } from 'react'
1
+ import React from 'react'
2
2
import _ from 'lodash'
3
3
4
4
import { consoleUtil } from 'test/utils'
@@ -37,12 +37,11 @@ export const propKeyAndValueToClassName = (Component, propKey, propValues, optio
37
37
* @param {String } propKey A props key.
38
38
* @param {Object } [options={}]
39
39
* @param {Object } [options.className=propKey] The className to assert exists.
40
- * @param {Number } [options.nestingLevel=0] The nesting level of the component.
41
40
* @param {Object } [options.requiredProps={}] Props required to render the component.
42
41
* @param {Object } [options.className=propKey] The className to assert exists.
43
42
*/
44
43
export const propKeyOnlyToClassName = ( Component , propKey , options = { } ) => {
45
- const { className = propKey , nestingLevel = 0 , requiredProps = { } } = options
44
+ const { className = propKey , requiredProps = { } } = options
46
45
const { assertRequired } = helpers ( 'propKeyOnlyToClassName' , Component )
47
46
48
47
describe ( `${ propKey } (common)` , ( ) => {
@@ -53,20 +52,25 @@ export const propKeyOnlyToClassName = (Component, propKey, options = {}) => {
53
52
54
53
it ( 'adds prop name to className' , ( ) => {
55
54
consoleUtil . disableOnce ( )
56
- shallow ( createElement ( Component , { ...requiredProps , [ propKey ] : true } ) , {
57
- autoNesting : true ,
58
- nestingLevel,
59
- } ) . should . have . className ( className )
55
+
56
+ const element = React . createElement ( Component , { ...requiredProps , [ propKey ] : true } )
57
+ const wrapper = mount ( element )
58
+
59
+ // ".should.have.className" with "mount" renderer does not handle properly cases when "className" contains
60
+ // multiple classes. That's why ".split()" is required.
61
+ className . split ( ' ' ) . forEach ( ( classNamePart ) => {
62
+ wrapper . childAt ( 0 ) . should . have . className ( classNamePart )
63
+ } )
60
64
} )
61
65
62
66
it ( 'does not add prop value to className' , ( ) => {
63
67
consoleUtil . disableOnce ( )
64
68
65
69
const value = 'foo-bar-baz'
66
- shallow ( createElement ( Component , { ...requiredProps , [ propKey ] : value } ) , {
67
- autoNesting : true ,
68
- nestingLevel ,
69
- } ) . should . not . have . className ( value )
70
+ const element = React . createElement ( Component , { ...requiredProps , [ propKey ] : value } )
71
+ const wrapper = mount ( element )
72
+
73
+ wrapper . childAt ( 0 ) . should . not . have . className ( value )
70
74
} )
71
75
} )
72
76
}
@@ -96,13 +100,15 @@ export const propKeyOrValueAndKeyToClassName = (Component, propKey, propValues,
96
100
} )
97
101
98
102
it ( 'adds only the name to className when true' , ( ) => {
99
- shallow ( createElement ( Component , { ...requiredProps , [ propKey ] : true } ) , {
103
+ shallow ( React . createElement ( Component , { ...requiredProps , [ propKey ] : true } ) , {
100
104
autoNesting : true ,
101
105
} ) . should . have . className ( className )
102
106
} )
103
107
104
108
it ( 'adds no className when false' , ( ) => {
105
- const wrapper = shallow ( createElement ( Component , { ...requiredProps , [ propKey ] : false } ) )
109
+ const wrapper = shallow (
110
+ React . createElement ( Component , { ...requiredProps , [ propKey ] : false } ) ,
111
+ )
106
112
107
113
wrapper . should . not . have . className ( className )
108
114
wrapper . should . not . have . className ( 'true' )
@@ -138,7 +144,7 @@ export const propValueOnlyToClassName = (Component, propKey, propValues, options
138
144
139
145
it ( 'adds prop value to className' , ( ) => {
140
146
propValues . forEach ( ( propValue ) => {
141
- shallow ( createElement ( Component , { ...requiredProps , [ propKey ] : propValue } ) , {
147
+ shallow ( React . createElement ( Component , { ...requiredProps , [ propKey ] : propValue } ) , {
142
148
autoNesting : true ,
143
149
nestingLevel,
144
150
} ) . should . have . className ( propValue )
@@ -149,7 +155,7 @@ export const propValueOnlyToClassName = (Component, propKey, propValues, options
149
155
consoleUtil . disableOnce ( )
150
156
151
157
propValues . forEach ( ( propValue ) => {
152
- shallow ( createElement ( Component , { ...requiredProps , [ propKey ] : propValue } ) , {
158
+ shallow ( React . createElement ( Component , { ...requiredProps , [ propKey ] : propValue } ) , {
153
159
autoNesting : true ,
154
160
nestingLevel,
155
161
} ) . should . not . have . className ( propKey )
0 commit comments