@@ -3,46 +3,12 @@ import * as React from 'react'
33
44import { render } from '../src/react'
55
6- function shallowWrapper ( elements : React . ReactNode [ ] ) {
6+ function shallowWrapper ( elements : React . ReactNode [ ] | React . ReactFragment ) {
77 return shallow ( React . createElement ( 'div' , null , elements ) )
88}
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-
4612 it ( 'should render a element node' , ( ) => {
4713 const div = document . createElement ( 'div' )
4814 const link = document . createElement ( 'a' )
@@ -97,4 +63,52 @@ describe('React', () => {
9763 expect ( wrapper . find ( 'span' ) . key ( ) ) . toEqual ( 'test' )
9864 } )
9965 } )
66+
67+ describe ( 'Options' , ( ) => {
68+ describe ( '#useFragment' , ( ) => {
69+ it ( 'should return a Fragment' , ( ) => {
70+ const div = document . createElement ( 'div' )
71+ const link = document . createElement ( 'a' )
72+ link . textContent = 'Link'
73+ div . appendChild ( link )
74+
75+ const wrapper = shallowWrapper ( render ( div . childNodes , { useFragment : true } ) )
76+ expect ( wrapper . find ( 'a' ) . text ( ) ) . toEqual ( 'Link' )
77+ } )
78+ } )
79+
80+ describe ( '#generatesKeys' , ( ) => {
81+ it ( 'should use key if provided' , ( ) => {
82+ const div = document . createElement ( 'div' )
83+ const link = document . createElement ( 'a' )
84+ link . textContent = 'Link'
85+ link . setAttribute ( 'key' , 'link' )
86+ div . appendChild ( link )
87+
88+ const wrapper = shallowWrapper ( render ( div . childNodes , { generatesKeys : true } ) )
89+ expect ( wrapper . find ( 'a' ) . key ( ) ) . toEqual ( 'link' )
90+ } )
91+
92+ it ( 'should use id if provided and key is not here' , ( ) => {
93+ const div = document . createElement ( 'div' )
94+ const link = document . createElement ( 'a' )
95+ link . textContent = 'Link'
96+ link . setAttribute ( 'id' , 'link' )
97+ div . appendChild ( link )
98+
99+ const wrapper = shallowWrapper ( render ( div . childNodes , { generatesKeys : true } ) )
100+ expect ( wrapper . find ( 'a' ) . key ( ) ) . toEqual ( 'link' )
101+ } )
102+
103+ it ( 'should use a random key if key nor id are specified' , ( ) => {
104+ const div = document . createElement ( 'div' )
105+ const link = document . createElement ( 'a' )
106+ link . textContent = 'Link'
107+ div . appendChild ( link )
108+
109+ const wrapper = shallowWrapper ( render ( div . childNodes , { generatesKeys : true } ) )
110+ expect ( wrapper . find ( 'a' ) . key ( ) ) . toHaveLength ( 5 )
111+ } )
112+ } )
113+ } )
100114} )
0 commit comments