File tree Expand file tree Collapse file tree 9 files changed +223
-9
lines changed
Expand file tree Collapse file tree 9 files changed +223
-9
lines changed Original file line number Diff line number Diff line change 11import React from 'react' ;
22import renderer from 'react-test-renderer' ;
33import Artboard from '../../src/components/Artboard' ;
4+ import StyleSheet from '../../src/stylesheet' ;
45
56describe ( '<Artboard />' , ( ) => {
67 it ( 'renders children' , ( ) => {
7- const tree = renderer . create ( < Artboard > < foo > < bar /> </ foo > </ Artboard > ) . toJSON ( ) ;
8+ const tree = renderer
9+ . create (
10+ < Artboard >
11+ < foo >
12+ < bar />
13+ </ foo >
14+ </ Artboard >
15+ )
16+ . toJSON ( ) ;
817
918 expect ( tree ) . toMatchSnapshot ( ) ;
1019 } ) ;
@@ -24,4 +33,32 @@ describe('<Artboard />', () => {
2433 expect ( tree ) . toMatchSnapshot ( ) ;
2534 } ) ;
2635 } ) ;
36+
37+ describe ( 'style' , ( ) => {
38+ const styles = StyleSheet . create ( {
39+ view : {
40+ flex : 1 ,
41+ } ,
42+ } ) ;
43+
44+ it ( 'accepts a plain object' , ( ) => {
45+ const tree = renderer . create ( < Artboard style = { { flex : 1 } } /> ) . toJSON ( ) ;
46+
47+ expect ( tree ) . toMatchSnapshot ( ) ;
48+ } ) ;
49+
50+ it ( 'accepts a StyleSheet ordinal' , ( ) => {
51+ const tree = renderer . create ( < Artboard style = { styles . view } /> ) . toJSON ( ) ;
52+
53+ expect ( tree ) . toMatchSnapshot ( ) ;
54+ } ) ;
55+
56+ it ( 'accepts an array of plain objects and/or StyleSheet ordinals' , ( ) => {
57+ const tree = renderer
58+ . create ( < Artboard style = { [ { flexGrow : 1 } , styles . view ] } /> )
59+ . toJSON ( ) ;
60+
61+ expect ( tree ) . toMatchSnapshot ( ) ;
62+ } ) ;
63+ } ) ;
2764} ) ;
Original file line number Diff line number Diff line change 11import React from 'react' ;
22import renderer from 'react-test-renderer' ;
33import Text from '../../src/components/Text' ;
4+ import StyleSheet from '../../src/stylesheet' ;
45
56describe ( '<Text />' , ( ) => {
67 it ( 'passes its children' , ( ) => {
@@ -22,4 +23,32 @@ describe('<Text />', () => {
2223 expect ( tree ) . toMatchSnapshot ( ) ;
2324 } ) ;
2425 } ) ;
26+
27+ describe ( 'style' , ( ) => {
28+ const styles = StyleSheet . create ( {
29+ view : {
30+ flex : 1 ,
31+ } ,
32+ } ) ;
33+
34+ it ( 'accepts a plain object' , ( ) => {
35+ const tree = renderer . create ( < Text style = { { flex : 1 } } /> ) . toJSON ( ) ;
36+
37+ expect ( tree ) . toMatchSnapshot ( ) ;
38+ } ) ;
39+
40+ it ( 'accepts a StyleSheet ordinal' , ( ) => {
41+ const tree = renderer . create ( < Text style = { styles . view } /> ) . toJSON ( ) ;
42+
43+ expect ( tree ) . toMatchSnapshot ( ) ;
44+ } ) ;
45+
46+ it ( 'accepts an array of plain objects and/or StyleSheet ordinals' , ( ) => {
47+ const tree = renderer
48+ . create ( < Text style = { [ { flexGrow : 1 } , styles . view ] } /> )
49+ . toJSON ( ) ;
50+
51+ expect ( tree ) . toMatchSnapshot ( ) ;
52+ } ) ;
53+ } ) ;
2554} ) ;
Original file line number Diff line number Diff line change 11import React from 'react' ;
22import renderer from 'react-test-renderer' ;
33import View from '../../src/components/View' ;
4+ import StyleSheet from '../../src/stylesheet' ;
45
56describe ( '<View />' , ( ) => {
67 it ( 'passes its children' , ( ) => {
@@ -22,4 +23,32 @@ describe('<View />', () => {
2223 expect ( tree ) . toMatchSnapshot ( ) ;
2324 } ) ;
2425 } ) ;
26+
27+ describe ( 'style' , ( ) => {
28+ const styles = StyleSheet . create ( {
29+ view : {
30+ flex : 1 ,
31+ } ,
32+ } ) ;
33+
34+ it ( 'accepts a plain object' , ( ) => {
35+ const tree = renderer . create ( < View style = { { flex : 1 } } /> ) . toJSON ( ) ;
36+
37+ expect ( tree ) . toMatchSnapshot ( ) ;
38+ } ) ;
39+
40+ it ( 'accepts a StyleSheet ordinal' , ( ) => {
41+ const tree = renderer . create ( < View style = { styles . view } /> ) . toJSON ( ) ;
42+
43+ expect ( tree ) . toMatchSnapshot ( ) ;
44+ } ) ;
45+
46+ it ( 'accepts an array of plain objects and/or StyleSheet ordinals' , ( ) => {
47+ const tree = renderer
48+ . create ( < View style = { [ { flexGrow : 1 } , styles . view ] } /> )
49+ . toJSON ( ) ;
50+
51+ expect ( tree ) . toMatchSnapshot ( ) ;
52+ } ) ;
53+ } ) ;
2554} ) ;
Original file line number Diff line number Diff line change @@ -19,3 +19,34 @@ exports[`<Artboard /> renders children 1`] = `
1919 </foo >
2020</artboard >
2121` ;
22+
23+ exports [` <Artboard /> style accepts a StyleSheet ordinal 1` ] = `
24+ <artboard
25+ name = " Artboard"
26+ style = {
27+ Object {
28+ " flex" : 1 ,
29+ }
30+ } />
31+ ` ;
32+
33+ exports [` <Artboard /> style accepts a plain object 1` ] = `
34+ <artboard
35+ name = " Artboard"
36+ style = {
37+ Object {
38+ " flex" : 1 ,
39+ }
40+ } />
41+ ` ;
42+
43+ exports [` <Artboard /> style accepts an array of plain objects and/or StyleSheet ordinals 1` ] = `
44+ <artboard
45+ name = " Artboard"
46+ style = {
47+ Object {
48+ " flex" : 1 ,
49+ " flexGrow" : 1 ,
50+ }
51+ } />
52+ ` ;
Original file line number Diff line number Diff line change @@ -20,3 +20,37 @@ exports[`<Text /> passes its children 1`] = `
2020 foo
2121</text >
2222` ;
23+
24+ exports [` <Text /> style accepts a StyleSheet ordinal 1` ] = `
25+ <text
26+ name = " Text"
27+ resizingConstraint = { undefined }
28+ style = {
29+ Object {
30+ " flex" : 1 ,
31+ }
32+ } />
33+ ` ;
34+
35+ exports [` <Text /> style accepts a plain object 1` ] = `
36+ <text
37+ name = " Text"
38+ resizingConstraint = { undefined }
39+ style = {
40+ Object {
41+ " flex" : 1 ,
42+ }
43+ } />
44+ ` ;
45+
46+ exports [` <Text /> style accepts an array of plain objects and/or StyleSheet ordinals 1` ] = `
47+ <text
48+ name = " Text"
49+ resizingConstraint = { undefined }
50+ style = {
51+ Object {
52+ " flex" : 1 ,
53+ " flexGrow" : 1 ,
54+ }
55+ } />
56+ ` ;
Original file line number Diff line number Diff line change @@ -20,3 +20,37 @@ exports[`<View /> passes its children 1`] = `
2020 foo
2121</view >
2222` ;
23+
24+ exports [` <View /> style accepts a StyleSheet ordinal 1` ] = `
25+ <view
26+ name = " View"
27+ resizingConstraint = { undefined }
28+ style = {
29+ Object {
30+ " flex" : 1 ,
31+ }
32+ } />
33+ ` ;
34+
35+ exports [` <View /> style accepts a plain object 1` ] = `
36+ <view
37+ name = " View"
38+ resizingConstraint = { undefined }
39+ style = {
40+ Object {
41+ " flex" : 1 ,
42+ }
43+ } />
44+ ` ;
45+
46+ exports [` <View /> style accepts an array of plain objects and/or StyleSheet ordinals 1` ] = `
47+ <view
48+ name = " View"
49+ resizingConstraint = { undefined }
50+ style = {
51+ Object {
52+ " flex" : 1 ,
53+ " flexGrow" : 1 ,
54+ }
55+ } />
56+ ` ;
Original file line number Diff line number Diff line change @@ -6,9 +6,16 @@ import ViewStylePropTypes from './ViewStylePropTypes';
66
77const propTypes = {
88 // TODO(lmr): do some nice warning stuff like RN does
9- style : PropTypes . shape ( {
10- ...ViewStylePropTypes ,
11- } ) ,
9+ style : PropTypes . oneOfType ( [
10+ PropTypes . shape ( { ...ViewStylePropTypes } ) ,
11+ PropTypes . arrayOf (
12+ PropTypes . oneOfType ( [
13+ PropTypes . shape ( { ...ViewStylePropTypes } ) ,
14+ PropTypes . number ,
15+ ] )
16+ ) ,
17+ PropTypes . number ,
18+ ] ) ,
1219 name : PropTypes . string ,
1320 children : PropTypes . node ,
1421} ;
Original file line number Diff line number Diff line change @@ -8,10 +8,17 @@ import ResizingConstraintPropTypes from './ResizingConstraintPropTypes';
88
99const propTypes = {
1010 // TODO(lmr): do some nice warning stuff like RN does
11- style : PropTypes . shape ( {
12- ...ViewStylePropTypes ,
13- ...TextStylePropTypes ,
14- } ) ,
11+ style : PropTypes . oneOfType ( [
12+ PropTypes . shape ( { ...ViewStylePropTypes , ...TextStylePropTypes } ) ,
13+ PropTypes . arrayOf (
14+ PropTypes . oneOfType ( [
15+ PropTypes . shape ( { ...ViewStylePropTypes , ...TextStylePropTypes } ) ,
16+ PropTypes . number ,
17+ ] )
18+ ) ,
19+ PropTypes . number ,
20+ ] ) ,
21+
1522 name : PropTypes . string ,
1623 resizingConstraint : PropTypes . shape ( {
1724 ...ResizingConstraintPropTypes ,
Original file line number Diff line number Diff line change @@ -9,7 +9,13 @@ const propTypes = {
99 // TODO(lmr): do some nice warning stuff like RN does
1010 style : PropTypes . oneOfType ( [
1111 PropTypes . shape ( { ...ViewStylePropTypes } ) ,
12- PropTypes . arrayOf ( PropTypes . shape ( { ...ViewStylePropTypes } ) ) ,
12+ PropTypes . arrayOf (
13+ PropTypes . oneOfType ( [
14+ PropTypes . shape ( { ...ViewStylePropTypes } ) ,
15+ PropTypes . number ,
16+ ] )
17+ ) ,
18+ PropTypes . number ,
1319 ] ) ,
1420 name : PropTypes . string ,
1521 resizingConstraint : PropTypes . shape ( {
You can’t perform that action at this time.
0 commit comments