1
1
jest . mock ( 'scheduler' , ( ) => require ( 'scheduler/unstable_mock' ) )
2
2
3
3
import * as React from 'react'
4
- import { Mesh } from 'three'
4
+ import { BoxBufferGeometry , Material , Mesh } from 'three'
5
5
6
6
import ReactThreeTestRenderer from '../index'
7
7
8
+ type ExampleComp = Mesh < BoxBufferGeometry , Material >
9
+
8
10
describe ( 'ReactThreeTestRenderer Core' , ( ) => {
9
11
it ( 'renders a simple component in default blocking mode' , async ( ) => {
10
12
const Mesh = ( ) => {
@@ -148,7 +150,7 @@ describe('ReactThreeTestRenderer Core', () => {
148
150
149
151
const renderer = await ReactThreeTestRenderer . create ( < Component /> )
150
152
151
- expect ( renderer . scene . children [ 0 ] . position . x ) . toEqual ( 7 )
153
+ expect ( renderer . scene . children [ 0 ] . instance . position . x ) . toEqual ( 7 )
152
154
expect ( renders ) . toBe ( 12 )
153
155
} )
154
156
@@ -161,8 +163,10 @@ describe('ReactThreeTestRenderer Core', () => {
161
163
</ mesh > ,
162
164
)
163
165
164
- expect ( renderer . scene . children [ 0 ] . material . type ) . toEqual ( 'MeshBasicMaterial' )
165
- expect ( renderer . scene . children [ 0 ] . material . name ) . toEqual ( 'basicMat' )
166
+ let childInstance = renderer . scene . children [ 0 ] . instance as ExampleComp
167
+
168
+ expect ( childInstance . material . type ) . toEqual ( 'MeshBasicMaterial' )
169
+ expect ( childInstance . material . name ) . toEqual ( 'basicMat' )
166
170
167
171
await renderer . update (
168
172
< mesh >
@@ -172,8 +176,10 @@ describe('ReactThreeTestRenderer Core', () => {
172
176
</ mesh > ,
173
177
)
174
178
175
- expect ( renderer . scene . children [ 0 ] . material . type ) . toEqual ( 'MeshStandardMaterial' )
176
- expect ( renderer . scene . children [ 0 ] . material . name ) . toEqual ( 'standardMat' )
179
+ childInstance = renderer . scene . children [ 0 ] . instance as ExampleComp
180
+
181
+ expect ( childInstance . material . type ) . toEqual ( 'MeshStandardMaterial' )
182
+ expect ( childInstance . material . name ) . toEqual ( 'standardMat' )
177
183
} )
178
184
179
185
it ( 'exposes the instance' , async ( ) => {
@@ -253,83 +259,7 @@ describe('ReactThreeTestRenderer Core', () => {
253
259
</ group > ,
254
260
)
255
261
256
- expect ( renderer . toTree ( ) ) . toEqual ( [
257
- {
258
- type : 'group' ,
259
- props : { } ,
260
- children : [
261
- {
262
- type : 'mesh' ,
263
- props : {
264
- [ 'position-z' ] : 12 ,
265
- } ,
266
- children : [
267
- {
268
- type : 'boxGeometry' ,
269
- props : {
270
- args : [ 2 , 2 ] ,
271
- attach : 'geometry' ,
272
- } ,
273
- children : [ ] ,
274
- } ,
275
- {
276
- type : 'meshBasicMaterial' ,
277
- props : {
278
- attach : 'material' ,
279
- } ,
280
- children : [ ] ,
281
- } ,
282
- ] ,
283
- } ,
284
- {
285
- type : 'mesh' ,
286
- props : {
287
- [ 'position-y' ] : 12 ,
288
- } ,
289
- children : [
290
- {
291
- type : 'boxGeometry' ,
292
- props : {
293
- args : [ 4 , 4 ] ,
294
- attach : 'geometry' ,
295
- } ,
296
- children : [ ] ,
297
- } ,
298
- {
299
- type : 'meshBasicMaterial' ,
300
- props : {
301
- attach : 'material' ,
302
- } ,
303
- children : [ ] ,
304
- } ,
305
- ] ,
306
- } ,
307
- {
308
- type : 'mesh' ,
309
- props : {
310
- [ 'position-x' ] : 12 ,
311
- } ,
312
- children : [
313
- {
314
- type : 'boxGeometry' ,
315
- props : {
316
- args : [ 6 , 6 ] ,
317
- attach : 'geometry' ,
318
- } ,
319
- children : [ ] ,
320
- } ,
321
- {
322
- type : 'meshBasicMaterial' ,
323
- props : {
324
- attach : 'material' ,
325
- } ,
326
- children : [ ] ,
327
- } ,
328
- ] ,
329
- } ,
330
- ] ,
331
- } ,
332
- ] )
262
+ expect ( renderer . toTree ( ) ) . toMatchSnapshot ( )
333
263
334
264
await renderer . update (
335
265
< group >
@@ -348,83 +278,7 @@ describe('ReactThreeTestRenderer Core', () => {
348
278
</ group > ,
349
279
)
350
280
351
- expect ( renderer . toTree ( ) ) . toEqual ( [
352
- {
353
- type : 'group' ,
354
- props : { } ,
355
- children : [
356
- {
357
- type : 'mesh' ,
358
- props : {
359
- [ 'rotation-x' ] : 1 ,
360
- } ,
361
- children : [
362
- {
363
- type : 'boxGeometry' ,
364
- props : {
365
- args : [ 6 , 6 ] ,
366
- attach : 'geometry' ,
367
- } ,
368
- children : [ ] ,
369
- } ,
370
- {
371
- type : 'meshBasicMaterial' ,
372
- props : {
373
- attach : 'material' ,
374
- } ,
375
- children : [ ] ,
376
- } ,
377
- ] ,
378
- } ,
379
- {
380
- type : 'mesh' ,
381
- props : {
382
- [ 'position-y' ] : 12 ,
383
- } ,
384
- children : [
385
- {
386
- type : 'boxGeometry' ,
387
- props : {
388
- args : [ 4 , 4 ] ,
389
- attach : 'geometry' ,
390
- } ,
391
- children : [ ] ,
392
- } ,
393
- {
394
- type : 'meshBasicMaterial' ,
395
- props : {
396
- attach : 'material' ,
397
- } ,
398
- children : [ ] ,
399
- } ,
400
- ] ,
401
- } ,
402
- {
403
- type : 'mesh' ,
404
- props : {
405
- [ 'position-x' ] : 12 ,
406
- } ,
407
- children : [
408
- {
409
- type : 'boxGeometry' ,
410
- props : {
411
- args : [ 2 , 2 ] ,
412
- attach : 'geometry' ,
413
- } ,
414
- children : [ ] ,
415
- } ,
416
- {
417
- type : 'meshBasicMaterial' ,
418
- props : {
419
- attach : 'material' ,
420
- } ,
421
- children : [ ] ,
422
- } ,
423
- ] ,
424
- } ,
425
- ] ,
426
- } ,
427
- ] )
281
+ expect ( renderer . toTree ( ) ) . toMatchSnapshot ( )
428
282
} )
429
283
430
284
it ( 'does the full lifecycle' , async ( ) => {
@@ -548,54 +402,7 @@ describe('ReactThreeTestRenderer Core', () => {
548
402
549
403
const renderer = await ReactThreeTestRenderer . create ( < Component /> )
550
404
551
- expect ( renderer . toTree ( ) ) . toEqual ( [
552
- {
553
- type : 'group' ,
554
- props : {
555
- position : [ 1 , 2 , 3 ] ,
556
- } ,
557
- children : [
558
- {
559
- type : 'mesh' ,
560
- props : { } ,
561
- children : [
562
- {
563
- type : 'bufferGeometry' ,
564
- props : { attach : 'geometry' } ,
565
- children : [
566
- {
567
- type : 'bufferAttribute' ,
568
- props : {
569
- attachObject : [ 'attributes' , 'position' ] ,
570
- array : vertices ,
571
- count : vertices . length / 3 ,
572
- itemSize : 3 ,
573
- } ,
574
- children : [ ] ,
575
- } ,
576
- ] ,
577
- } ,
578
- {
579
- type : 'meshBasicMaterial' ,
580
- props : {
581
- attach : 'material' ,
582
- color : 'hotpink' ,
583
- } ,
584
- children : [ ] ,
585
- } ,
586
- ] ,
587
- } ,
588
- {
589
- type : 'color' ,
590
- props : {
591
- attach : 'background' ,
592
- args : [ 0 , 0 , 255 ] ,
593
- } ,
594
- children : [ ] ,
595
- } ,
596
- ] ,
597
- } ,
598
- ] )
405
+ expect ( renderer . toTree ( ) ) . toMatchSnapshot ( )
599
406
} )
600
407
601
408
it ( 'toTree() handles complicated tree of fragments' , async ( ) => {
@@ -617,50 +424,7 @@ describe('ReactThreeTestRenderer Core', () => {
617
424
</ > ,
618
425
)
619
426
620
- expect ( renderer . toTree ( ) ) . toEqual ( [
621
- {
622
- type : 'group' ,
623
- props : { } ,
624
- children : [
625
- {
626
- type : 'color' ,
627
- props : {
628
- args : [ 0 , 0 , 0 ] ,
629
- attach : 'background' ,
630
- } ,
631
- children : [ ] ,
632
- } ,
633
- ] ,
634
- } ,
635
- {
636
- type : 'group' ,
637
- props : { } ,
638
- children : [
639
- {
640
- type : 'color' ,
641
- props : {
642
- args : [ 0 , 0 , 255 ] ,
643
- attach : 'background' ,
644
- } ,
645
- children : [ ] ,
646
- } ,
647
- ] ,
648
- } ,
649
- {
650
- type : 'group' ,
651
- props : { } ,
652
- children : [
653
- {
654
- type : 'color' ,
655
- props : {
656
- args : [ 255 , 0 , 0 ] ,
657
- attach : 'background' ,
658
- } ,
659
- children : [ ] ,
660
- } ,
661
- ] ,
662
- } ,
663
- ] )
427
+ expect ( renderer . toTree ( ) ) . toMatchSnapshot ( )
664
428
} )
665
429
666
430
it ( 'root instance and refs return the same value' , async ( ) => {
0 commit comments