@@ -3,51 +3,59 @@ import React from 'react';
3
3
import ReactDOM from 'react-dom' ;
4
4
5
5
let x = 0 ;
6
- function createComponent ( name , done ) {
6
+ function createComponentWithOpts ( opts ) {
7
7
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 ) ,
20
9
} ) , { React, ReactDOM } ) ;
21
10
}
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
+ }
22
25
23
26
describe ( '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
+
24
42
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' ) ; } ) ;
26
44
ReactDOM . render ( < Comp > < div /> </ Comp > , window . fixture ) ;
27
45
} ) ;
28
46
29
47
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' ) ; } ) ;
31
49
ReactDOM . render ( < Comp oncustomevent = "test" /> , window . fixture ) ;
32
50
} ) ;
33
51
34
52
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 ) ) ;
36
54
ReactDOM . render ( < Comp test = "test" /> , window . fixture ) ;
37
55
} ) ;
38
56
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
-
49
57
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' ) ) ;
51
59
ReactDOM . render ( < Comp test = "test" /> , window . fixture ) ;
52
60
} ) ;
53
61
} ) ;
0 commit comments