@@ -16,6 +16,7 @@ var emptyFunction = require('emptyFunction');
16
16
describe ( 'ReactDOMTextarea' , function ( ) {
17
17
var React ;
18
18
var ReactDOM ;
19
+ var ReactDOMServer ;
19
20
var ReactLink ;
20
21
var ReactTestUtils ;
21
22
@@ -24,6 +25,7 @@ describe('ReactDOMTextarea', function() {
24
25
beforeEach ( function ( ) {
25
26
React = require ( 'React' ) ;
26
27
ReactDOM = require ( 'ReactDOM' ) ;
28
+ ReactDOMServer = require ( 'ReactDOMServer' ) ;
27
29
ReactLink = require ( 'ReactLink' ) ;
28
30
ReactTestUtils = require ( 'ReactTestUtils' ) ;
29
31
@@ -50,7 +52,7 @@ describe('ReactDOMTextarea', function() {
50
52
51
53
// Changing `defaultValue` should change if no value set.
52
54
renderTextarea ( < textarea defaultValue = "gorilla" /> , container , true ) ;
53
- expect ( node . value ) . toEqual ( 'gorilla ' ) ;
55
+ expect ( node . value ) . toEqual ( 'giraffe ' ) ;
54
56
55
57
node . value = 'cat' ;
56
58
@@ -113,6 +115,13 @@ describe('ReactDOMTextarea', function() {
113
115
expect ( node . value ) . toEqual ( 'gorilla' ) ;
114
116
} ) ;
115
117
118
+ it ( 'should render value for SSR' , function ( ) {
119
+ var image = ReactDOMServer . renderToString ( < textarea defaultValue = "1" /> ) ;
120
+ var div = document . createElement ( 'div' ) ;
121
+ div . innerHTML = image ;
122
+ expect ( div . firstChild . innerHTML ) . toBe ( '1' ) ;
123
+ } ) ;
124
+
116
125
it ( 'should allow setting `value` to `true`' , function ( ) {
117
126
var container = document . createElement ( 'div' ) ;
118
127
var stub = < textarea value = "giraffe" onChange = { emptyFunction } /> ;
@@ -163,27 +172,27 @@ describe('ReactDOMTextarea', function() {
163
172
it ( 'should take updates to `defaultValue` for uncontrolled textarea' , function ( ) {
164
173
var container = document . createElement ( 'div' ) ;
165
174
166
- var node = ReactDOM . render ( < textarea type = "text" defaultValue = "0" /> , container ) ;
175
+ var node = ReactDOM . render ( < textarea defaultValue = "0" /> , container ) ;
167
176
168
177
expect ( node . value ) . toBe ( '0' ) ;
169
178
170
- ReactDOM . render ( < textarea type = "text" defaultValue = "1" /> , container ) ;
179
+ ReactDOM . render ( < textarea defaultValue = "1" /> , container ) ;
171
180
172
- expect ( node . value ) . toBe ( '1 ' ) ;
181
+ expect ( node . value ) . toBe ( '0 ' ) ;
173
182
} ) ;
174
183
175
184
it ( 'should take updates to children in lieu of `defaultValue` for uncontrolled textarea' , function ( ) {
176
185
var container = document . createElement ( 'div' ) ;
177
186
178
- var node = ReactDOM . render ( < textarea type = "text" defaultValue = "0" /> , container ) ;
187
+ var node = ReactDOM . render ( < textarea defaultValue = "0" /> , container ) ;
179
188
180
189
expect ( node . value ) . toBe ( '0' ) ;
181
190
182
191
spyOn ( console , 'error' ) ; // deprecation warning for `children` content
183
192
184
- ReactDOM . render ( < textarea type = "text" > 1</ textarea > , container ) ;
193
+ ReactDOM . render ( < textarea > 1</ textarea > , container ) ;
185
194
186
- expect ( node . value ) . toBe ( '1 ' ) ;
195
+ expect ( node . value ) . toBe ( '0 ' ) ;
187
196
} ) ;
188
197
189
198
it ( 'should not incur unnecessary DOM mutations' , function ( ) {
@@ -228,9 +237,9 @@ describe('ReactDOMTextarea', function() {
228
237
expect ( console . error . argsForCall . length ) . toBe ( 1 ) ;
229
238
expect ( node . value ) . toBe ( 'giraffe' ) ;
230
239
231
- // Changing children should cause value to change (new behavior of `defaultValue`)
240
+ // Changing children should do nothing, it functions like `defaultValue`.
232
241
stub = ReactDOM . render ( < textarea > gorilla</ textarea > , container ) ;
233
- expect ( node . value ) . toEqual ( 'gorilla ' ) ;
242
+ expect ( node . value ) . toEqual ( 'giraffe ' ) ;
234
243
} ) ;
235
244
236
245
it ( 'should not keep value when switching to uncontrolled element if not changed' , function ( ) {
@@ -242,7 +251,7 @@ describe('ReactDOMTextarea', function() {
242
251
243
252
ReactDOM . render ( < textarea defaultValue = "gorilla" > </ textarea > , container ) ;
244
253
245
- expect ( node . value ) . toEqual ( 'gorilla ' ) ;
254
+ expect ( node . value ) . toEqual ( 'kitten ' ) ;
246
255
} ) ;
247
256
248
257
it ( 'should keep value when switching to uncontrolled element if changed' , function ( ) {
0 commit comments