@@ -103,7 +103,7 @@ describe('UNIT: API', function () {
103103
104104 describe ( 'component()' , function ( ) {
105105
106- var testId = 'api-vm -test' ,
106+ var testId = 'api-component -test' ,
107107 testId2 = testId + '2' ,
108108 opts = {
109109 className : 'hihi' ,
@@ -143,6 +143,64 @@ describe('UNIT: API', function () {
143143
144144 } )
145145
146+ describe ( 'element()' , function ( ) {
147+
148+ var testId = 'api-element-test' ,
149+ testId2 = testId + '2' ,
150+ testId3 = testId + '3' ,
151+ opts = {
152+ className : 'hihi' ,
153+ scope : { hi : 'ok' }
154+ } ,
155+ Test = Seed . extend ( opts ) ,
156+ utils = require ( 'seed/src/utils' )
157+
158+ it ( 'should register a Custom Element constructor' , function ( ) {
159+ Seed . element ( testId , Test )
160+ assert . strictEqual ( utils . elements [ testId ] , Test )
161+ } )
162+
163+ it ( 'should also work with option objects' , function ( ) {
164+ Seed . element ( testId2 , opts )
165+ assert . ok ( utils . elements [ testId2 ] . prototype instanceof Seed )
166+ } )
167+
168+ it ( 'should accept simple function as-is' , function ( ) {
169+ var fn = function ( el ) {
170+ el . className = 'hihi3'
171+ el . textContent = 'ok3'
172+ }
173+ Seed . element ( testId3 , fn )
174+ assert . strictEqual ( utils . elements [ testId3 ] , fn )
175+ } )
176+
177+ it ( 'should retrieve the VM if has only one arg' , function ( ) {
178+ assert . strictEqual ( Seed . element ( testId ) , Test )
179+ } )
180+
181+ it ( 'should work with custom tag names' , function ( ) {
182+
183+ mock ( testId , '<' + testId + '>{{hi}}</' + testId + '>' )
184+ var t = new Seed ( { el : '#' + testId } ) ,
185+ child = t . $el . querySelector ( testId )
186+ assert . strictEqual ( child . className , 'hihi' )
187+ assert . strictEqual ( child . textContent , 'ok' )
188+
189+ mock ( testId2 , '<' + testId2 + '>{{hi}}</' + testId2 + '>' )
190+ var t2 = new Seed ( { el : '#' + testId2 } ) ,
191+ child2 = t2 . $el . querySelector ( testId2 )
192+ assert . strictEqual ( child2 . className , 'hihi' )
193+ assert . strictEqual ( child2 . textContent , 'ok' )
194+
195+ mock ( testId3 , '<' + testId3 + '></' + testId3 + '>' )
196+ var t3 = new Seed ( { el : '#' + testId3 } ) ,
197+ child3 = t3 . $el . querySelector ( testId3 )
198+ assert . strictEqual ( child3 . className , 'hihi3' )
199+ assert . strictEqual ( child3 . textContent , 'ok3' )
200+ } )
201+
202+ } )
203+
146204 describe ( 'partial()' , function ( ) {
147205
148206 var testId = 'api-partial-test' ,
@@ -588,6 +646,66 @@ describe('UNIT: API', function () {
588646 } )
589647
590648 } )
649+
650+ describe ( 'elements' , function ( ) {
651+
652+ it ( 'should allow the VM to use private custom elements' , function ( ) {
653+ var Child = Seed . extend ( {
654+ scope : {
655+ name : 'child'
656+ }
657+ } )
658+ var Parent = Seed . extend ( {
659+ template : '<p>{{name}}</p><child>{{name}}</child>' ,
660+ scope : {
661+ name : 'dad'
662+ } ,
663+ elements : {
664+ child : Child
665+ }
666+ } )
667+ var p = new Parent ( )
668+ assert . strictEqual ( p . $el . querySelector ( 'p' ) . textContent , 'dad' )
669+ assert . strictEqual ( p . $el . querySelector ( 'child' ) . textContent , 'child' )
670+ } )
671+
672+ it ( 'should work with plain option object' , function ( ) {
673+ var Parent = Seed . extend ( {
674+ template : '<p>{{name}}</p><child>{{name}}</child>' ,
675+ scope : {
676+ name : 'dad'
677+ } ,
678+ elements : {
679+ child : {
680+ scope : {
681+ name : 'child'
682+ }
683+ }
684+ }
685+ } )
686+ var p = new Parent ( )
687+ assert . strictEqual ( p . $el . querySelector ( 'p' ) . textContent , 'dad' )
688+ assert . strictEqual ( p . $el . querySelector ( 'child' ) . textContent , 'child' )
689+ } )
690+
691+ it ( 'should work with a simple function' , function ( ) {
692+ var Parent = Seed . extend ( {
693+ template : '<p>{{name}}</p><child></child>' ,
694+ scope : {
695+ name : 'dad'
696+ } ,
697+ elements : {
698+ child : function ( el ) {
699+ el . textContent = 'child'
700+ }
701+ }
702+ } )
703+ var p = new Parent ( )
704+ assert . strictEqual ( p . $el . querySelector ( 'p' ) . textContent , 'dad' )
705+ assert . strictEqual ( p . $el . querySelector ( 'child' ) . textContent , 'child' )
706+ } )
707+
708+ } )
591709
592710 describe ( 'partials' , function ( ) {
593711
0 commit comments