react-element-to-string
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -18,3 +18,7 @@ var React = require('react'); | ||
function showName(element) { | ||
return element.type.displayName || element.type.name || element.type; | ||
var type = element.type; | ||
if (type.displayName) return type.displayName; | ||
if (type.name) return type.name; | ||
if (typeof type == 'string') return type; | ||
return 'Unknown'; | ||
} | ||
@@ -21,0 +25,0 @@ |
{ | ||
"name": "react-element-to-string", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Convert a ReactElement into a nice string useful for debugging", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -83,2 +83,19 @@ var React = require('react'); | ||
it('should handle function children', function() { | ||
function Func() { return <hr />; } | ||
expect(str(<Basic><Func /></Basic>)) | ||
.to.eql('<Basic>\n <Func />\n</Basic>'); | ||
}); | ||
it('should handle component without displayName children', function() { | ||
var A = (function() { | ||
// eslint-disable-next-line react/display-name | ||
return React.createClass({ | ||
render: function() { return null; } | ||
}); | ||
})(); | ||
expect(str(<Basic><A /></Basic>)) | ||
.to.eql('<Basic>\n <Unknown />\n</Basic>'); | ||
}); | ||
it('should show ReactElement with text children', function() { | ||
@@ -85,0 +102,0 @@ expect(str(<Basic>Stuff{"&"}Nonsense</Basic>)) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9813
205