@@ -3,51 +3,59 @@ import React from 'react';
33import ReactDOM from 'react-dom' ;
44
55let x = 0 ;
6- function createComponent ( name , done ) {
6+ function createComponentWithOpts ( opts ) {
77 return reactify ( document . registerElement ( `x-props-${ x ++ } ` , {
8- prototype : Object . create ( HTMLElement . prototype , {
9- [ name ] : {
10- get ( ) {
11- return 'test' ;
12- } ,
13- set ( value ) {
14- if ( done ) {
15- done ( this , value ) ;
16- }
17- } ,
18- } ,
19- } ) ,
8+ prototype : Object . create ( HTMLElement . prototype , opts ) ,
209 } ) , { React, ReactDOM } ) ;
2110}
11+ function createComponentWithProp ( name , done ) {
12+ return createComponentWithOpts ( {
13+ [ name ] : {
14+ get ( ) {
15+ return 'test' ;
16+ } ,
17+ set ( value ) {
18+ if ( done ) {
19+ done ( this , value ) ;
20+ }
21+ } ,
22+ } ,
23+ } ) ;
24+ }
2225
2326describe ( 'props' , ( ) => {
27+ it ( 'should set style (object)' , ( ) => {
28+ const Comp = createComponentWithOpts ( { } ) ;
29+ ReactDOM . render ( < Comp style = { { backgroundColor : 'black' , width : 1 } } /> , window . fixture ) ;
30+ const elem = window . fixture . firstChild ;
31+ expect ( elem . style . backgroundColor ) . to . equal ( 'black' ) ;
32+ expect ( elem . style . width ) . to . equal ( '1px' ) ;
33+ } ) ;
34+
35+ it ( 'should set className' , ( ) => {
36+ const Comp = createComponentWithOpts ( { } ) ;
37+ ReactDOM . render ( < Comp className = "test" /> , window . fixture ) ;
38+ const elem = window . fixture . firstChild ;
39+ expect ( elem . getAttribute ( 'class' ) ) . to . equal ( 'test' ) ;
40+ } ) ;
41+
2442 it ( 'should not set children' , ( ) => {
25- const Comp = createComponent ( 'children' , ( ) => { throw new Error ( 'set children' ) ; } ) ;
43+ const Comp = createComponentWithProp ( 'children' , ( ) => { throw new Error ( 'set children' ) ; } ) ;
2644 ReactDOM . render ( < Comp > < div /> </ Comp > , window . fixture ) ;
2745 } ) ;
2846
2947 it ( 'should not set events' , ( ) => {
30- const Comp = createComponent ( 'oncustomevent' , ( ) => { throw new Error ( 'set oncustomevent' ) ; } ) ;
48+ const Comp = createComponentWithProp ( 'oncustomevent' , ( ) => { throw new Error ( 'set oncustomevent' ) ; } ) ;
3149 ReactDOM . render ( < Comp oncustomevent = "test" /> , window . fixture ) ;
3250 } ) ;
3351
3452 it ( 'should not set attributes' , ( ) => {
35- const Comp = createComponent ( 'test' , elem => expect ( elem . hasAttribute ( 'test' ) ) . to . equal ( false ) ) ;
53+ const Comp = createComponentWithProp ( 'test' , elem => expect ( elem . hasAttribute ( 'test' ) ) . to . equal ( false ) ) ;
3654 ReactDOM . render ( < Comp test = "test" /> , window . fixture ) ;
3755 } ) ;
3856
39- it ( 'should set style as an attribute (object)' , ( ) => {
40- const Comp = createComponent ( 'style' , elem => expect ( elem . style . display ) . to . equal ( 'block' ) ) ;
41- ReactDOM . render ( < Comp style = { { display : 'block' } } /> , window . fixture ) ;
42- } ) ;
43-
44- it ( 'should set style as an attribute (string)' , ( ) => {
45- const Comp = createComponent ( 'style' , elem => expect ( elem . style . display ) . to . equal ( 'block' ) ) ;
46- ReactDOM . render ( < Comp style = "style: block" /> , window . fixture ) ;
47- } ) ;
48-
4957 it ( 'should set properties for anything else' , ( ) => {
50- const Comp = createComponent ( 'test' , ( elem , value ) => expect ( value ) . to . equal ( 'test' ) ) ;
58+ const Comp = createComponentWithProp ( 'test' , ( elem , value ) => expect ( value ) . to . equal ( 'test' ) ) ;
5159 ReactDOM . render ( < Comp test = "test" /> , window . fixture ) ;
5260 } ) ;
5361} ) ;
0 commit comments