@@ -9,14 +9,48 @@ function shallowWrapper(elements: React.ReactNode[]) {
99
1010describe ( 'React' , ( ) => {
1111 describe ( '#render' , ( ) => {
12+ describe ( 'generatesKeys' , ( ) => {
13+ it ( 'should use key if provided' , ( ) => {
14+ const div = document . createElement ( 'div' )
15+ const link = document . createElement ( 'a' )
16+ link . textContent = 'Link'
17+ link . setAttribute ( 'key' , 'link' )
18+ div . appendChild ( link )
19+
20+ const wrapper = shallowWrapper ( render ( div . childNodes , { generatesKeys : true } ) )
21+ expect ( wrapper . find ( 'a' ) . key ( ) ) . toEqual ( 'link' )
22+ } )
23+
24+ it ( 'should use id if provided and key is not here' , ( ) => {
25+ const div = document . createElement ( 'div' )
26+ const link = document . createElement ( 'a' )
27+ link . textContent = 'Link'
28+ link . setAttribute ( 'id' , 'link' )
29+ div . appendChild ( link )
30+
31+ const wrapper = shallowWrapper ( render ( div . childNodes , { generatesKeys : true } ) )
32+ expect ( wrapper . find ( 'a' ) . key ( ) ) . toEqual ( 'link' )
33+ } )
34+
35+ it ( 'should use a random key if key nor id are specified' , ( ) => {
36+ const div = document . createElement ( 'div' )
37+ const link = document . createElement ( 'a' )
38+ link . textContent = 'Link'
39+ div . appendChild ( link )
40+
41+ const wrapper = shallowWrapper ( render ( div . childNodes , { generatesKeys : true } ) )
42+ expect ( wrapper . find ( 'a' ) . key ( ) ) . toHaveLength ( 5 )
43+ } )
44+ } )
45+
1246 it ( 'should render a element node' , ( ) => {
1347 const div = document . createElement ( 'div' )
1448 const link = document . createElement ( 'a' )
1549 link . textContent = 'Link'
1650 link . setAttribute ( 'key' , 'link' )
1751 div . appendChild ( link )
1852
19- const wrapper = shallowWrapper ( render ( div . childNodes ) )
53+ const wrapper = shallowWrapper ( render ( div . childNodes , { } ) )
2054 expect ( wrapper . find ( 'a' ) . text ( ) ) . toEqual ( 'Link' )
2155 } )
2256
@@ -26,7 +60,7 @@ describe('React', () => {
2660 newLine . setAttribute ( 'key' , 'test' )
2761 div . appendChild ( newLine )
2862
29- const wrapper = shallowWrapper ( render ( div . childNodes ) )
63+ const wrapper = shallowWrapper ( render ( div . childNodes , { } ) )
3064 expect ( wrapper . find ( 'br' ) ) . toHaveLength ( 1 )
3165 } )
3266
@@ -35,7 +69,7 @@ describe('React', () => {
3569 const text = document . createTextNode ( 'Text' )
3670 div . appendChild ( text )
3771
38- const wrapper = shallowWrapper ( render ( div . childNodes ) )
72+ const wrapper = shallowWrapper ( render ( div . childNodes , { } ) )
3973 expect ( wrapper . text ( ) ) . toEqual ( 'Text' )
4074 } )
4175
@@ -44,7 +78,7 @@ describe('React', () => {
4478 const comment = document . createComment ( 'Comment' )
4579 div . appendChild ( comment )
4680
47- const wrapper = shallowWrapper ( render ( div . childNodes ) )
81+ const wrapper = shallowWrapper ( render ( div . childNodes , { } ) )
4882 expect ( wrapper . children ( ) ) . toHaveLength ( 0 )
4983 } )
5084
@@ -56,7 +90,7 @@ describe('React', () => {
5690 span . setAttribute ( 'key' , 'test' )
5791 div . appendChild ( span )
5892
59- const wrapper = shallowWrapper ( render ( div . childNodes ) )
93+ const wrapper = shallowWrapper ( render ( div . childNodes , { } ) )
6094 expect ( wrapper . find ( 'span' ) ) . toHaveLength ( 1 )
6195 expect ( wrapper . find ( 'span' ) . prop ( 'htmlFor' ) ) . toEqual ( 'test' )
6296 expect ( wrapper . find ( 'span' ) . prop ( 'className' ) ) . toEqual ( 'test' )
0 commit comments