@@ -222,6 +222,34 @@ suite('Component', function () {
222222 assert . equal ( data [ 0 ] , 'a' ) ;
223223 assert . notEqual ( data , array ) ;
224224 } ) ;
225+
226+ test ( 'does not override set data with mixin' , function ( done ) {
227+ var el ;
228+ var mixinEl ;
229+
230+ el = helpers . entityFactory ( ) ;
231+
232+ registerComponent ( 'dummy' , {
233+ schema : {
234+ color : { default : 'blue' } ,
235+ size : { default : 5 }
236+ }
237+ } ) ;
238+
239+ mixinEl = document . createElement ( 'a-mixin' ) ;
240+ mixinEl . setAttribute ( 'id' , 'mixindummy' ) ;
241+ mixinEl . setAttribute ( 'dummy' , 'size: 1' ) ;
242+ el . sceneEl . appendChild ( mixinEl ) ;
243+
244+ el . addEventListener ( 'loaded' , ( ) => {
245+ el . setAttribute ( 'mixin' , 'mixindummy' ) ;
246+ el . setAttribute ( 'dummy' , 'size' , 20 ) ;
247+ el . setAttribute ( 'dummy' , 'color' , 'red' ) ;
248+ assert . equal ( el . getAttribute ( 'dummy' ) . color , 'red' ) ;
249+ assert . equal ( el . getAttribute ( 'dummy' ) . size , 20 ) ;
250+ done ( ) ;
251+ } ) ;
252+ } ) ;
225253 } ) ;
226254
227255 suite ( 'updateProperties' , function ( ) {
@@ -406,7 +434,7 @@ suite('Component', function () {
406434 assert . equal ( el . components . dummy . data , el . components . dummy . schema . default ) ;
407435 } ) ;
408436
409- test ( 'a plain object schema default is cloned into data' , function ( ) {
437+ test ( 'clones plain object schema default into data' , function ( ) {
410438 registerComponent ( 'dummy' , {
411439 schema : { type : 'vec3' , default : { x : 1 , y : 1 , z : 1 } }
412440 } ) ;
@@ -418,21 +446,25 @@ suite('Component', function () {
418446 assert . deepEqual ( el . components . dummy . data , { x : 1 , y : 1 , z : 1 } ) ;
419447 } ) ;
420448
421- test ( 'do not clone properties from attrValue into data that are not plain objects' , function ( ) {
449+ test ( 'does not clone properties from attrValue into data that are not plain objects' , function ( ) {
450+ var attrValue ;
451+ var data ;
452+ var el ;
453+
422454 registerComponent ( 'dummy' , {
423455 schema : {
424456 color : { default : 'blue' } ,
425457 direction : { type : 'vec3' } ,
426458 el : { type : 'selector' , default : 'body' }
427459 }
428460 } ) ;
429- var el = document . createElement ( 'a-entity' ) ;
461+ el = document . createElement ( 'a-entity' ) ;
430462 el . hasLoaded = true ;
431463 el . setAttribute ( 'dummy' , '' ) ;
432464 assert . notOk ( el . components . dummy . attrValue . el ) ;
433- // The direction property will be preserved
434- // across updateProperties calls but cloned
435- // into a different object
465+
466+ // Direction property preserved across updateProperties calls but cloned into a different
467+ // object.
436468 el . components . dummy . updateProperties ( {
437469 color : 'green' ,
438470 direction : { x : 1 , y : 1 , z : 1 } ,
@@ -442,16 +474,16 @@ suite('Component', function () {
442474 color : 'red' ,
443475 el : document . head
444476 } ) ;
445- var data = el . getAttribute ( 'dummy' ) ;
446- var attrValue = el . components . dummy . attrValue ;
477+ data = el . getAttribute ( 'dummy' ) ;
478+ attrValue = el . components . dummy . attrValue ;
447479 assert . notEqual ( data , attrValue ) ;
448480 assert . equal ( data . color , attrValue . color ) ;
449481 // HTMLElement not cloned in attrValue, reference is shared instead.
450482 assert . equal ( data . el , attrValue . el ) ;
451483 assert . equal ( data . el . constructor , HTMLHeadElement ) ;
452- assert . notEqual ( data . direction , attrValue . direction ) ;
453484 assert . deepEqual ( data . direction , { x : 1 , y : 1 , z : 1 } ) ;
454485 assert . deepEqual ( attrValue . direction , { x : 1 , y : 1 , z : 1 } ) ;
486+
455487 el . components . dummy . updateProperties ( {
456488 color : 'red' ,
457489 direction : { x : 1 , y : 1 , z : 1 }
0 commit comments