@@ -289,25 +289,28 @@ suite('Component', function () {
289289 } ) ;
290290
291291 test ( 'does not emit componentchanged for multi-prop if not changed' , function ( done ) {
292- el . addEventListener ( 'componentinitialized' , function ( evt ) {
292+ function componentChanged ( evt ) {
293293 if ( evt . detail . name !== 'material' ) { return ; }
294+ el . removeEventListener ( 'componentchanged' , componentChanged ) ;
295+ // Should not reach here.
296+ assert . equal ( true , false , 'Component should not have emitted changed.' ) ;
297+ }
294298
295- el . addEventListener ( 'componentchanged' , function ( evt ) {
296- if ( evt . detail . name !== 'material' ) { return ; }
297- // Should not reach here.
298- assert . equal ( true , false , 'Component should not have emitted changed.' ) ;
299- } ) ;
300-
301- // Update.
299+ function componentInitialized ( evt ) {
300+ if ( evt . detail . name !== 'material' ) { return ; }
301+ el . addEventListener ( 'componentchanged' , componentChanged ) ;
302302 el . setAttribute ( 'material' , 'color' , 'red' ) ;
303+ }
303304
304- // Have `done()` race with the failing assertion in the event handler.
305- setTimeout ( ( ) => {
306- done ( ) ;
307- } , 100 ) ;
308- } ) ;
309- // Initialization.
305+ el . addEventListener ( 'componentinitialized' , componentInitialized ) ;
310306 el . setAttribute ( 'material' , 'color' , 'red' ) ;
307+
308+ // Have `done()` race with the failing assertion in the event handler.
309+ setTimeout ( ( ) => {
310+ el . removeEventListener ( 'componentchanged' , componentChanged ) ;
311+ el . removeEventListener ( 'componentinitialized' , componentInitialized ) ;
312+ done ( ) ;
313+ } , 100 ) ;
311314 } ) ;
312315
313316 test ( 'does not update for multi-prop if not changed' , function ( done ) {
@@ -358,25 +361,27 @@ suite('Component', function () {
358361 } ) ;
359362
360363 test ( 'does not emit componentchanged for single-prop if not changed' , function ( done ) {
361- el . addEventListener ( 'componentinitialized' , function ( evt ) {
362- if ( evt . detail . name !== 'position' ) { return ; }
364+ function componentInitialized ( evt ) {
365+ if ( evt . detail . name !== 'visible' ) { return ; }
366+ el . addEventListener ( 'componentchanged' , componentChanged ) ;
367+ el . setAttribute ( 'visible' , false ) ;
368+ }
363369
364- el . addEventListener ( 'componentchanged' , function ( evt ) {
365- if ( evt . detail . name !== 'position ' ) { return ; }
366- // Should not reach here.
367- assert . equal ( true , false , 'Component should not have emitted changed.' ) ;
368- } ) ;
370+ function componentChanged ( evt ) {
371+ if ( evt . detail . name !== 'visible ' ) { return ; }
372+ // Should not reach here.
373+ assert . equal ( true , false , 'Component should not have emitted changed.' ) ;
374+ }
369375
370- // Update.
371- el . setAttribute ( 'position ' , { x : 1 , y : 2 , z : 3 } ) ;
376+ el . addEventListener ( 'componentinitialized' , componentInitialized ) ;
377+ el . setAttribute ( 'visible ' , false ) ;
372378
373- // Have `done()` race with the failing assertion in the event handler.
374- setTimeout ( ( ) => {
375- done ( ) ;
376- } , 100 ) ;
377- } ) ;
378- // Initialization.
379- el . setAttribute ( 'position' , { x : 1 , y : 2 , z : 3 } ) ;
379+ // Have `done()` race with the failing assertion in the event handler.
380+ setTimeout ( ( ) => {
381+ el . removeEventListener ( 'componentinitialized' , componentInitialized ) ;
382+ el . removeEventListener ( 'componentchanged' , componentChanged ) ;
383+ done ( ) ;
384+ } , 100 ) ;
380385 } ) ;
381386
382387 test ( 'does not emit componentchanged for value if not changed' , function ( done ) {
@@ -437,8 +442,6 @@ suite('Component', function () {
437442 } ) ;
438443
439444 test ( 'does not clone properties from attrValue into data that are not plain objects' , function ( ) {
440- var attrValue ;
441- var data ;
442445 var el ;
443446 registerComponent ( 'dummy' , {
444447 schema : {
@@ -458,6 +461,19 @@ suite('Component', function () {
458461 var el ;
459462 var data ;
460463
464+ registerComponent ( 'dummy' , {
465+ schema : {
466+ color : { type : 'string' } ,
467+ direction : { type : 'vec3' } ,
468+ el : { type : 'selector' , default : 'body' }
469+ }
470+ } ) ;
471+
472+ el = document . createElement ( 'a-entity' ) ;
473+ el . hasLoaded = true ;
474+ el . setAttribute ( 'dummy' , '' ) ;
475+ assert . notOk ( el . components . dummy . attrValue . el ) ;
476+
461477 // Direction property preserved across updateProperties calls but cloned into a different
462478 // object.
463479 el . components . dummy . updateProperties ( {
@@ -702,8 +718,8 @@ suite('Component', function () {
702718
703719 suite ( 'updateProperties' , function ( ) {
704720 setup ( function ( done ) {
705- components . dummy = undefined ;
706721 var el = this . el = entityFactory ( ) ;
722+ components . dummy = undefined ;
707723 if ( el . hasLoaded ) { done ( ) ; }
708724 el . addEventListener ( 'loaded' , function ( ) { done ( ) ; } ) ;
709725 } ) ;
@@ -749,7 +765,7 @@ suite('Component', function () {
749765 el . addEventListener ( 'loaded' , function ( ) { done ( ) ; } ) ;
750766 } ) ;
751767
752- test ( 'init is only called once if the init routine sets the component' , function ( ) {
768+ test ( 'init is called once if the init routine sets the component' , function ( ) {
753769 var initCanaryStub = sinon . stub ( ) ;
754770 var el = this . el ;
755771 registerComponent ( 'dummy' , {
@@ -1016,15 +1032,19 @@ suite('Component', function () {
10161032 test ( 'applies default array property types with no defined value' , function ( done ) {
10171033 var el ;
10181034 registerComponent ( 'test' , {
1019- schema : { default : [ 'foo' ] } ,
1035+ schema : {
1036+ arr : { default : [ 'foo' ] }
1037+ } ,
10201038
10211039 update : function ( ) {
1022- assert . equal ( this . data [ 0 ] , 'foo' ) ;
1040+ assert . equal ( this . data . arr [ 0 ] , 'foo' ) ;
10231041 done ( ) ;
10241042 }
10251043 } ) ;
10261044 el = entityFactory ( ) ;
1027- el . setAttribute ( 'test' , '' ) ;
1045+ el . addEventListener ( 'loaded' , ( ) => {
1046+ el . setAttribute ( 'test' , '' ) ;
1047+ } ) ;
10281048 } ) ;
10291049} ) ;
10301050
0 commit comments