260
expect(container.firstChild.hasAttribute('height')).toBe(false);
261
});
262
263
+ it('should remove known SVG camel case attributes', function() {
264
+ var container = document.createElement('div');
265
+ ReactDOM.render(<svg viewBox="0 0 100 100" />, container);
266
+
267
+ expect(container.firstChild.hasAttribute('viewBox')).toBe(true);
268
+ ReactDOM.render(<svg />, container);
269
+ expect(container.firstChild.hasAttribute('viewBox')).toBe(false);
270
+ });
271
+
272
+ it('should remove known SVG hyphenated attributes', function() {
273
+ var container = document.createElement('div');
274
+ ReactDOM.render(<svg clip-path="0 0 100 100" />, container);
275
+
276
+ expect(container.firstChild.hasAttribute('clip-path')).toBe(true);
277
+ ReactDOM.render(<svg />, container);
278
+ expect(container.firstChild.hasAttribute('clip-path')).toBe(false);
279
+ });
280
+
281
+ it('should remove arbitrary SVG hyphenated attributes', function() {
282
+ var container = document.createElement('div');
283
+ ReactDOM.render(<svg the-word="the-bird" />, container);
284
+
285
+ expect(container.firstChild.hasAttribute('the-word')).toBe(true);
286
+ ReactDOM.render(<svg />, container);
287
+ expect(container.firstChild.hasAttribute('the-word')).toBe(false);
288
+ });
289
+
290
+ it('should remove arbitrary SVG camel case attributes', function() {
291
+ var container = document.createElement('div');
292
+ ReactDOM.render(<svg theWord="theBird" />, container);
293
+
294
+ expect(container.firstChild.hasAttribute('theWord')).toBe(true);
295
+ ReactDOM.render(<svg />, container);
296
+ expect(container.firstChild.hasAttribute('theWord')).toBe(false);
297
+ });
298
+
299
+ it('should remove SVG attributes that should have been hyphenated', function() {
300
+ spyOn(console, 'error');
301
+ var container = document.createElement('div');
302
+ ReactDOM.render(<svg clipPath="0 0 100 100" />, container);
303
+ expect(console.error.argsForCall.length).toBe(1);
304
+ expect(console.error.argsForCall[0][0]).toContain('clipPath');
305
+ expect(console.error.argsForCall[0][0]).toContain('clip-path');
306
+
307
+ expect(container.firstChild.hasAttribute('clip-path')).toBe(true);
308
+ ReactDOM.render(<svg />, container);
309
+ expect(container.firstChild.hasAttribute('clip-path')).toBe(false);
310
+ });
311
+
312
+ it('should remove namespaced SVG attributes', function() {
313
+ var container = document.createElement('div');
314
+ ReactDOM.render(
315
+ <svg>
316
+ <image xlinkHref="http://i.imgur.com/w7GCRPb.png" />
317
+ </svg>,
318
+ container
319
+ );
320
+
321
+ expect(container.firstChild.firstChild.hasAttributeNS(
322
+ 'http://www.w3.org/1999/xlink',
323
+ 'href'
324
+ )).toBe(true);
325
+ ReactDOM.render(<svg><image /></svg>, container);
326
+ expect(container.firstChild.firstChild.hasAttributeNS(
327
+ 'http://www.w3.org/1999/xlink',
328
+ 'href'
329
+ )).toBe(false);
330
+ });
331
+
332
it('should remove properties', function() {
333
var container = document.createElement('div');
334
ReactDOM.render(<div className="monkey" />, container);
400
expect(container.childNodes[0].getAttribute('myattr')).toBe('myval');
401
});
402
403
+ it('should update known hyphenated attributes for SVG tags', function() {
404
+ var container = document.createElement('div');
405
+
406
+ var beforeUpdate = React.createElement('svg', {}, null);
407
+ ReactDOM.render(beforeUpdate, container);
408
+
409
+ var afterUpdate = <svg clip-path="url(#starlet)" />;
410
+ ReactDOM.render(afterUpdate, container);
411
+
412
+ expect(container.childNodes[0].getAttribute('clip-path')).toBe(
413
+ 'url(#starlet)'
414
+ );
415
+ });
416
+
417
+ it('should update camel case attributes for SVG tags', function() {
418
+ var container = document.createElement('div');
419
+
420
+ var beforeUpdate = React.createElement('svg', {}, null);
421
+ ReactDOM.render(beforeUpdate, container);
422
+
423
+ var afterUpdate = <svg viewBox="0 0 100 100" />;
424
+ ReactDOM.render(afterUpdate, container);
425
+
426
+ expect(container.childNodes[0].getAttribute('viewBox')).toBe(
427
+ '0 0 100 100'
428
+ );
429
+ });
430
+
431
+ it('should warn camel casing hyphenated attributes for SVG tags', function() {
432
+ spyOn(console, 'error');
433
+ var container = document.createElement('div');
434
+
435
+ var beforeUpdate = React.createElement('svg', {}, null);
436
+ ReactDOM.render(beforeUpdate, container);
437
+
438
+ var afterUpdate = <svg clipPath="url(#starlet)" />;
439
+ ReactDOM.render(afterUpdate, container);
440
+
441
+ expect(container.childNodes[0].getAttribute('clip-path')).toBe(
442
+ 'url(#starlet)'
443
+ );
444
+ expect(console.error.argsForCall.length).toBe(1);
445
+ expect(console.error.argsForCall[0][0]).toContain('clipPath');
446
+ expect(console.error.argsForCall[0][0]).toContain('clip-path');
447
+ });
448
+
449
+ it('should update arbitrary hyphenated attributes for SVG tags', function() {
450
+ var container = document.createElement('div');
451
+
452
+ var beforeUpdate = React.createElement('svg', {}, null);
453
+ ReactDOM.render(beforeUpdate, container);
454
+
455
+ var afterUpdate = <svg the-word="the-bird" />;
456
+ ReactDOM.render(afterUpdate, container);
457
+
458
+ expect(container.childNodes[0].getAttribute('the-word')).toBe('the-bird');
459
+ });
460
+
461
+ it('should update arbitrary camel case attributes for SVG tags', function() {
462
+ var container = document.createElement('div');
463
+
464
+ var beforeUpdate = React.createElement('svg', {}, null);
465
+ ReactDOM.render(beforeUpdate, container);
466
+
467
+ var afterUpdate = <svg theWord="theBird" />;
468
+ ReactDOM.render(afterUpdate, container);
469
+
470
+ expect(container.childNodes[0].getAttribute('theWord')).toBe('theBird');
471
+ });
472
+
473
+ it('should update namespaced SVG attributes', function() {
474
+ var container = document.createElement('div');
475
+
476
+ var beforeUpdate = (
477
+ <svg>
478
+ <image xlinkHref="http://i.imgur.com/w7GCRPb.png" />
479
+ </svg>
480
+ );
481
+ ReactDOM.render(beforeUpdate, container);
482
+
483
+ var afterUpdate = (
484
+ <svg>
485
+ <image xlinkHref="http://i.imgur.com/JvqCM2p.png" />
486
+ </svg>
487
+ );
488
+ ReactDOM.render(afterUpdate, container);
489
+
490
+ expect(container.firstChild.firstChild.getAttributeNS(
491
+ 'http://www.w3.org/1999/xlink',
492
+ 'href'
493
+ )).toBe('http://i.imgur.com/JvqCM2p.png');
494
+ });
495
+
496
it('should clear all the styles when removing `style`', function() {
497
var styles = {display: 'none', color: 'red'};
498
var container = document.createElement('div');