@@ -34,8 +34,8 @@ suite('components/Image', () => {
34
34
test ( 'sets background image when value is an object' , ( ) => {
35
35
const defaultSource = { uri : 'https://google.com/favicon.ico' } ;
36
36
const image = shallow ( < Image defaultSource = { defaultSource } /> ) ;
37
- const backgroundImage = StyleSheet . flatten ( image . prop ( 'style' ) ) . backgroundImage ;
38
- assert ( backgroundImage . indexOf ( defaultSource . uri ) > - 1 ) ;
37
+ const style = StyleSheet . flatten ( image . prop ( 'style' ) ) ;
38
+ assert ( style . backgroundImage . indexOf ( defaultSource . uri ) > - 1 ) ;
39
39
} ) ;
40
40
41
41
test ( 'sets background image when value is a string' , ( ) => {
@@ -45,13 +45,30 @@ suite('components/Image', () => {
45
45
const backgroundImage = StyleSheet . flatten ( image . prop ( 'style' ) ) . backgroundImage ;
46
46
assert ( backgroundImage . indexOf ( defaultSource ) > - 1 ) ;
47
47
} ) ;
48
+
49
+ test ( 'sets "height" and "width" styles if missing' , ( ) => {
50
+ const defaultSource = { uri : 'https://google.com/favicon.ico' , height : 10 , width : 20 } ;
51
+ const image = mount ( < Image defaultSource = { defaultSource } /> ) ;
52
+ const html = image . html ( ) ;
53
+ assert ( html . indexOf ( 'height: 10px' ) > - 1 ) ;
54
+ assert ( html . indexOf ( 'width: 20px' ) > - 1 ) ;
55
+ } ) ;
56
+
57
+ test ( 'does not override "height" and "width" styles' , ( ) => {
58
+ const defaultSource = { uri : 'https://google.com/favicon.ico' , height : 10 , width : 20 } ;
59
+ const image = mount ( < Image defaultSource = { defaultSource } style = { { height : 20 , width : 40 } } /> ) ;
60
+ const html = image . html ( ) ;
61
+ assert ( html . indexOf ( 'height: 20px' ) > - 1 ) ;
62
+ assert ( html . indexOf ( 'width: 40px' ) > - 1 ) ;
63
+ } ) ;
48
64
} ) ;
49
65
50
66
test ( 'prop "onError"' , function ( done ) {
51
67
this . timeout ( 5000 ) ;
52
- mount ( < Image onError = { onError } source = { { uri : 'https://google.com/favicon.icox' } } /> ) ;
68
+ const image = mount ( < Image onError = { onError } source = { { uri : 'https://google.com/favicon.icox' } } /> ) ;
53
69
function onError ( e ) {
54
- assert . equal ( e . nativeEvent . type , 'error' ) ;
70
+ assert . ok ( e . nativeEvent . error ) ;
71
+ image . unmount ( ) ;
55
72
done ( ) ;
56
73
}
57
74
} ) ;
@@ -63,6 +80,7 @@ suite('components/Image', () => {
63
80
assert . equal ( e . nativeEvent . type , 'load' ) ;
64
81
const hasBackgroundImage = ( image . html ( ) ) . indexOf ( 'url("https://google.com/favicon.ico")' ) > - 1 ;
65
82
assert . equal ( hasBackgroundImage , true ) ;
83
+ image . unmount ( ) ;
66
84
done ( ) ;
67
85
}
68
86
} ) ;
@@ -74,6 +92,7 @@ suite('components/Image', () => {
74
92
assert . ok ( true ) ;
75
93
const hasBackgroundImage = ( image . html ( ) ) . indexOf ( 'url("https://google.com/favicon.ico")' ) > - 1 ;
76
94
assert . equal ( hasBackgroundImage , true ) ;
95
+ image . unmount ( ) ;
77
96
done ( ) ;
78
97
}
79
98
} ) ;
@@ -121,21 +140,23 @@ suite('components/Image', () => {
121
140
122
141
test ( 'sets background image when value is an object' , ( done ) => {
123
142
const source = { uri : 'https://google.com/favicon.ico' } ;
124
- mount ( < Image onLoad = { onLoad } source = { source } /> ) ;
143
+ const image = mount ( < Image onLoad = { onLoad } source = { source } /> ) ;
125
144
function onLoad ( e ) {
126
145
const src = e . nativeEvent . target . src ;
127
146
assert . equal ( src , source . uri ) ;
147
+ image . unmount ( ) ;
128
148
done ( ) ;
129
149
}
130
150
} ) ;
131
151
132
152
test ( 'sets background image when value is a string' , ( done ) => {
133
153
// emulate require-ed asset
134
154
const source = 'https://google.com/favicon.ico' ;
135
- mount ( < Image onLoad = { onLoad } source = { source } /> ) ;
155
+ const image = mount ( < Image onLoad = { onLoad } source = { source } /> ) ;
136
156
function onLoad ( e ) {
137
157
const src = e . nativeEvent . target . src ;
138
158
assert . equal ( src , source ) ;
159
+ image . unmount ( ) ;
139
160
done ( ) ;
140
161
}
141
162
} ) ;
0 commit comments