1- import { mount } from 'enzyme'
2- import { set } from 'object-path'
1+ import { mount } from 'enzyme'
2+ import { set } from 'object-path'
33import React from 'react'
4- import { Textbox } from 'tcomb-form-native/lib/components'
4+ import { Textbox } from 'tcomb-form-native/lib/components'
55import transform from 'tcomb-json-schema'
66import templates from 'tcomb-form-native/lib/templates/bootstrap'
77
@@ -11,106 +11,99 @@ import Builder from '..'
1111const fixture = require ( './fixture/1.json' )
1212
1313
14- describe ( 'load definition' , function ( )
15- {
16- test ( 'no definition' , function ( )
17- {
18- const wrapper = mount ( < Builder templates = { templates } /> )
14+ describe ( 'load definition' , ( ) => {
15+ test ( 'no definition' , ( ) => {
16+ const wrapper = mount ( < Builder templates = { templates } /> )
1917
2018 expect ( wrapper ) . toMatchSnapshot ( )
2119 } )
2220
23- describe ( 'JSON string' , function ( )
24- {
21+ describe ( 'JSON string' , ( ) => {
2522 const json = JSON . stringify ( fixture )
2623
27- test ( 'prop' , function ( )
28- {
29- const wrapper = mount ( < Builder templates = { templates } type = { json } /> )
24+ test ( 'prop' , ( ) => {
25+ const wrapper = mount ( < Builder templates = { templates } type = { json } /> )
3026
3127 expect ( wrapper ) . toMatchSnapshot ( )
3228 } )
3329
34- test ( 'body' , function ( )
35- {
30+ test ( 'body' , ( ) => {
3631 const wrapper = mount ( < Builder templates = { templates } > { json } </ Builder > )
3732
3833 expect ( wrapper ) . toMatchSnapshot ( )
3934 } )
4035 } )
4136
42- describe ( 'JSON object' , function ( )
43- {
44- test ( 'prop' , function ( )
45- {
46- const wrapper = mount ( < Builder templates = { templates } type = { fixture } /> )
37+ describe ( 'JSON object' , ( ) => {
38+ test ( 'prop' , ( ) => {
39+ const wrapper = mount ( < Builder templates = { templates } type = { fixture } /> )
4740
4841 expect ( wrapper ) . toMatchSnapshot ( )
4942 } )
5043
51- test ( 'body' , function ( )
52- {
44+ test ( 'body' , ( ) => {
5345 const wrapper = mount ( < Builder templates = { templates } > { fixture } </ Builder > )
5446
5547 expect ( wrapper ) . toMatchSnapshot ( )
5648 } )
5749 } )
5850
59- describe ( 'tcomb object' , function ( )
60- {
51+ describe ( 'tcomb object' , ( ) => {
6152 const tcomb = transform ( fixture )
6253
63- test ( 'prop' , function ( )
64- {
65- const wrapper = mount ( < Builder templates = { templates } type = { tcomb } /> )
54+ test ( 'prop' , ( ) => {
55+ const wrapper = mount ( < Builder templates = { templates } type = { tcomb } /> )
6656
6757 expect ( wrapper ) . toMatchSnapshot ( )
6858 } )
6959
70- test ( 'body' , function ( )
71- {
60+ test ( 'body' , ( ) => {
7261 const wrapper = mount ( < Builder templates = { templates } > { tcomb } </ Builder > )
7362
7463 expect ( wrapper ) . toMatchSnapshot ( )
7564 } )
7665 } )
7766} )
7867
79- test ( 'update definition' , function ( )
80- {
81- const wrapper = mount ( < Builder templates = { templates } type = { fixture } /> )
68+ test ( 'update definition' , ( ) => {
69+ const wrapper = mount ( < Builder templates = { templates } type = { fixture } /> )
8270
8371 expect ( wrapper ) . toMatchSnapshot ( )
8472
85- wrapper . setProps ( { type : require ( './fixture/2.json' ) } )
73+ wrapper . setProps ( { type : require ( './fixture/2.json' ) } )
8674
8775 expect ( wrapper ) . toMatchSnapshot ( )
8876} )
8977
90- describe ( 'custom factories' , function ( )
91- {
92- const factories = { customFactory : Textbox }
78+ describe ( 'custom factories' , ( ) => {
79+ const factories = { customFactory : Textbox }
9380
94- test ( 'root element' , function ( )
95- {
96- const wrapper = mount ( < Builder templates = { templates }
97- type = { require ( './fixture/3.json' ) } factories = { factories } /> )
81+ test ( 'root element' , ( ) => {
82+ const wrapper = mount ( < Builder
83+ templates = { templates }
84+ type = { require ( './fixture/3.json' ) }
85+ factories = { factories }
86+ /> )
9887
9988 expect ( wrapper ) . toMatchSnapshot ( )
10089 } )
10190
102- test ( 'object property' , function ( )
103- {
104- const wrapper = mount ( < Builder templates = { templates }
105- type = { require ( './fixture/4.json' ) } factories = { factories } /> )
91+ test ( 'object property' , ( ) => {
92+ const wrapper = mount ( < Builder
93+ templates = { templates }
94+ type = { require ( './fixture/4.json' ) }
95+ factories = { factories }
96+ /> )
10697
10798 expect ( wrapper ) . toMatchSnapshot ( )
10899 } )
109100
110- test ( 'array item' , function ( )
111- {
112- const wrapper = mount ( < Builder templates = { templates }
113- type = { require ( './fixture/5.json' ) } factories = { factories } /> )
101+ test ( 'array item' , ( ) => {
102+ const wrapper = mount ( < Builder
103+ templates = { templates }
104+ type = { require ( './fixture/5.json' ) }
105+ factories = { factories }
106+ /> )
114107
115108 expect ( wrapper ) . toMatchSnapshot ( )
116109
@@ -120,77 +113,80 @@ describe('custom factories', function()
120113 expect ( wrapper ) . toMatchSnapshot ( )
121114 } )
122115
123- test ( 'unknown factory' , function ( )
124- {
116+ test ( 'unknown factory' , ( ) => {
125117 const type = require ( './fixture/6.json' )
126118
127- function wrapper ( )
128- {
129- mount ( < Builder type = { type } templates = { templates } factories = { factories } /> )
119+ function wrapper ( ) {
120+ mount ( < Builder type = { type } templates = { templates } factories = { factories } /> )
130121 }
131122
132123 expect ( wrapper ) . toThrowErrorMatchingSnapshot ( )
133124 } )
134125
135- test ( 'explicit factory' , function ( )
136- {
126+ test ( 'explicit factory' , ( ) => {
137127 const type = require ( './fixture/1.json' )
138128 type . factory = Textbox
139129
140- const wrapper = mount ( < Builder templates = { templates } type = { type } /> )
130+ const wrapper = mount ( < Builder templates = { templates } type = { type } /> )
141131
142132 expect ( wrapper ) . toMatchSnapshot ( )
143133 } )
144134} )
145135
146- describe ( 'predefined options' , function ( )
147- {
148- const factories = { customFactory : Textbox }
136+ describe ( 'predefined options' , ( ) => {
137+ const factories = { customFactory : Textbox }
149138
150- test ( 'object property' , function ( )
151- {
152- const options = { fields : { } }
139+ test ( 'object property' , ( ) => {
140+ const options = { fields : { } }
153141 const type = require ( './fixture/8.json' )
154142
155- const wrapper = mount ( < Builder templates = { templates } factories = { factories }
156- options = { options } type = { type } /> )
143+ const wrapper = mount ( < Builder
144+ templates = { templates }
145+ factories = { factories }
146+ options = { options }
147+ type = { type }
148+ /> )
157149
158150 expect ( wrapper ) . toMatchSnapshot ( )
159151 } )
160152
161- test ( 'array item' , function ( )
162- {
153+ test ( 'array item' , ( ) => {
163154 const options = { }
164155 const type = require ( './fixture/7.json' )
165156
166- const wrapper = mount ( < Builder templates = { templates } factories = { factories }
167- options = { options } type = { type } /> )
157+ const wrapper = mount ( < Builder
158+ templates = { templates }
159+ factories = { factories }
160+ options = { options }
161+ type = { type }
162+ /> )
168163
169164 expect ( wrapper ) . toMatchSnapshot ( )
170165 } )
171166} )
172167
173- test ( 'component options' , function ( )
174- {
168+ test ( 'component options' , ( ) => {
175169 const tcombFormComponent = jest . fn ( ( ) => null )
176170
177171 const customType = Builder . t . subtype ( Builder . t . Str , s => s , 'customType' )
178172 customType . getTcombFormFactory = jest . fn ( ( ) => tcombFormComponent )
179173
180- const types = { customType}
174+ const types = { customType }
181175 const type = require ( './fixture/9.json' )
182176
183- const wrapper = mount ( < Builder templates = { templates } type = { type }
184- types = { types } /> )
177+ const wrapper = mount ( < Builder
178+ templates = { templates }
179+ type = { type }
180+ types = { types }
181+ /> )
185182
186183 expect ( wrapper ) . toMatchSnapshot ( )
187184
188185 expect ( tcombFormComponent . mock . calls . length ) . toBe ( 1 )
189- expect ( tcombFormComponent . mock . calls [ 0 ] [ 0 ] ) . toMatchObject ( { options : { componentOption : 'blah' } } )
186+ expect ( tcombFormComponent . mock . calls [ 0 ] [ 0 ] ) . toMatchObject ( { options : { componentOption : 'blah' } } )
190187} )
191188
192- test ( 'disable `submit` button if form is not valid' , function ( )
193- {
189+ test ( 'disable `submit` button if form is not valid' , ( ) => {
194190 const onSubmit = jest . fn ( )
195191 set ( onSubmit , 'meta.type.meta.name' , 'submit' )
196192
@@ -199,19 +195,21 @@ test('disable `submit` button if form is not valid', function()
199195 const submit = Builder . t . subtype ( Builder . t . Nil , s => s , 'submit' )
200196 submit . getTcombFormFactory = jest . fn ( ( ) => tcombFormComponent )
201197
202- const types = { submit}
198+ const types = { submit }
203199 const type = require ( './fixture/10.json' )
204200
205- const wrapper = mount ( < Builder onSubmit = { onSubmit } templates = { templates }
206- type = { type } types = { types } /> )
201+ const wrapper = mount ( < Builder
202+ onSubmit = { onSubmit }
203+ templates = { templates }
204+ type = { type }
205+ types = { types }
206+ /> )
207207
208208 expect ( wrapper ) . toMatchSnapshot ( )
209209} )
210210
211- describe ( 'clean labels' , function ( )
212- {
213- test ( "don't show 'optional' suffix on root `submit` button" , function ( )
214- {
211+ describe ( 'clean labels' , ( ) => {
212+ test ( "don't show 'optional' suffix on root `submit` button" , ( ) => {
215213 const onSubmit = jest . fn ( )
216214 set ( onSubmit , 'meta.type.meta.name' , 'submit' )
217215
@@ -220,17 +218,20 @@ describe('clean labels', function()
220218 const submit = Builder . t . subtype ( Builder . t . Nil , s => s , 'submit' )
221219 submit . getTcombFormFactory = jest . fn ( ( ) => tcombFormComponent )
222220
223- const types = { submit}
221+ const types = { submit }
224222 const type = require ( './fixture/10.json' )
225223
226- const wrapper = mount ( < Builder onSubmit = { onSubmit } templates = { templates }
227- type = { type } types = { types } /> )
224+ const wrapper = mount ( < Builder
225+ onSubmit = { onSubmit }
226+ templates = { templates }
227+ type = { type }
228+ types = { types }
229+ /> )
228230
229231 expect ( wrapper ) . toMatchSnapshot ( )
230232 } )
231233
232- test ( "don't show 'optional' suffix on nested `submit` button" , function ( )
233- {
234+ test ( "don't show 'optional' suffix on nested `submit` button" , ( ) => {
234235 const onSubmit = jest . fn ( )
235236 set ( onSubmit , 'meta.type.meta.name' , 'submit' )
236237
@@ -239,20 +240,26 @@ describe('clean labels', function()
239240 const submit = Builder . t . subtype ( Builder . t . Nil , s => s , 'submit' )
240241 submit . getTcombFormFactory = jest . fn ( ( ) => tcombFormComponent )
241242
242- const types = { submit}
243+ const types = { submit }
243244 const type = require ( './fixture/11.json' )
244245
245- const wrapper = mount ( < Builder onSubmit = { onSubmit } templates = { templates }
246- type = { type } types = { types } /> )
246+ const wrapper = mount ( < Builder
247+ onSubmit = { onSubmit }
248+ templates = { templates }
249+ type = { type }
250+ types = { types }
251+ /> )
247252
248253 expect ( wrapper ) . toMatchSnapshot ( )
249254 } )
250255
251- test . skip ( 'tuple' , function ( )
252- {
256+ test . skip ( 'tuple' , ( ) => {
253257 const type = require ( './fixture/12.json' )
254258
255- const wrapper = mount ( < Builder templates = { templates } type = { type } /> )
259+ const wrapper = mount ( < Builder
260+ templates = { templates }
261+ type = { type }
262+ /> )
256263
257264 expect ( wrapper ) . toMatchSnapshot ( )
258265 } )
0 commit comments