@@ -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
@@ -48,9 +50,9 @@ describe('ReactDOMTextarea', function() {
48
50
49
51
expect ( node . value ) . toBe ( 'giraffe' ) ;
50
52
51
- // Changing `defaultValue` should change if no value set .
53
+ // Changing `defaultValue` should do nothing .
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
@@ -85,6 +87,14 @@ describe('ReactDOMTextarea', function() {
85
87
expect ( node . value ) . toBe ( 'foobar' ) ;
86
88
} ) ;
87
89
90
+ it ( 'should set defaultValue' , function ( ) {
91
+ var container = document . createElement ( 'div' ) ;
92
+ ReactDOM . render ( < textarea defaultValue = "foo" /> , container ) ;
93
+ ReactDOM . render ( < textarea defaultValue = "bar" /> , container ) ;
94
+ ReactDOM . render ( < textarea defaultValue = "noise" /> , container ) ;
95
+ expect ( container . firstChild . defaultValue ) . toBe ( 'noise' ) ;
96
+ } ) ;
97
+
88
98
it ( 'should not render value as an attribute' , function ( ) {
89
99
var stub = < textarea value = "giraffe" onChange = { emptyFunction } /> ;
90
100
var node = renderTextarea ( stub ) ;
@@ -113,6 +123,14 @@ describe('ReactDOMTextarea', function() {
113
123
expect ( node . value ) . toEqual ( 'gorilla' ) ;
114
124
} ) ;
115
125
126
+ it ( 'should render value for SSR' , function ( ) {
127
+ var image = ReactDOMServer . renderToString ( < textarea defaultValue = "1" /> ) ;
128
+ var div = document . createElement ( 'div' ) ;
129
+ div . innerHTML = image ;
130
+ expect ( div . firstChild . innerHTML ) . toBe ( '1' ) ;
131
+ expect ( div . firstChild . getAttribute ( 'defaultValue' ) ) . toBe ( null ) ;
132
+ } ) ;
133
+
116
134
it ( 'should allow setting `value` to `true`' , function ( ) {
117
135
var container = document . createElement ( 'div' ) ;
118
136
var stub = < textarea value = "giraffe" onChange = { emptyFunction } /> ;
@@ -163,27 +181,27 @@ describe('ReactDOMTextarea', function() {
163
181
it ( 'should take updates to `defaultValue` for uncontrolled textarea' , function ( ) {
164
182
var container = document . createElement ( 'div' ) ;
165
183
166
- var node = ReactDOM . render ( < textarea type = "text" defaultValue = "0" /> , container ) ;
184
+ var node = ReactDOM . render ( < textarea defaultValue = "0" /> , container ) ;
167
185
168
186
expect ( node . value ) . toBe ( '0' ) ;
169
187
170
- ReactDOM . render ( < textarea type = "text" defaultValue = "1" /> , container ) ;
188
+ ReactDOM . render ( < textarea defaultValue = "1" /> , container ) ;
171
189
172
- expect ( node . value ) . toBe ( '1 ' ) ;
190
+ expect ( node . value ) . toBe ( '0 ' ) ;
173
191
} ) ;
174
192
175
193
it ( 'should take updates to children in lieu of `defaultValue` for uncontrolled textarea' , function ( ) {
176
194
var container = document . createElement ( 'div' ) ;
177
195
178
- var node = ReactDOM . render ( < textarea type = "text" defaultValue = "0" /> , container ) ;
196
+ var node = ReactDOM . render ( < textarea defaultValue = "0" /> , container ) ;
179
197
180
198
expect ( node . value ) . toBe ( '0' ) ;
181
199
182
200
spyOn ( console , 'error' ) ; // deprecation warning for `children` content
183
201
184
- ReactDOM . render ( < textarea type = "text" > 1</ textarea > , container ) ;
202
+ ReactDOM . render ( < textarea > 1</ textarea > , container ) ;
185
203
186
- expect ( node . value ) . toBe ( '1 ' ) ;
204
+ expect ( node . value ) . toBe ( '0 ' ) ;
187
205
} ) ;
188
206
189
207
it ( 'should not incur unnecessary DOM mutations' , function ( ) {
@@ -228,9 +246,9 @@ describe('ReactDOMTextarea', function() {
228
246
expect ( console . error . argsForCall . length ) . toBe ( 1 ) ;
229
247
expect ( node . value ) . toBe ( 'giraffe' ) ;
230
248
231
- // Changing children should cause value to change (new behavior of `defaultValue`)
249
+ // Changing children should do nothing, it functions like `defaultValue`.
232
250
stub = ReactDOM . render ( < textarea > gorilla</ textarea > , container ) ;
233
- expect ( node . value ) . toEqual ( 'gorilla ' ) ;
251
+ expect ( node . value ) . toEqual ( 'giraffe ' ) ;
234
252
} ) ;
235
253
236
254
it ( 'should not keep value when switching to uncontrolled element if not changed' , function ( ) {
@@ -242,7 +260,7 @@ describe('ReactDOMTextarea', function() {
242
260
243
261
ReactDOM . render ( < textarea defaultValue = "gorilla" > </ textarea > , container ) ;
244
262
245
- expect ( node . value ) . toEqual ( 'gorilla ' ) ;
263
+ expect ( node . value ) . toEqual ( 'kitten ' ) ;
246
264
} ) ;
247
265
248
266
it ( 'should keep value when switching to uncontrolled element if changed' , function ( ) {
0 commit comments