@@ -44,6 +44,39 @@ test('should warn when passed `source`', () => {
44
44
console . warn = warn
45
45
} )
46
46
47
+ test ( 'should warn when passed non-string children (number)' , ( ) => {
48
+ const { error, warn} = console
49
+ console . error = jest . fn ( )
50
+ console . warn = jest . fn ( )
51
+ // @ts -ignore runtime
52
+ expect ( renderHTML ( < Markdown children = { 1 } /> ) ) . toEqual ( '' )
53
+ expect ( console . warn ) . toHaveBeenCalledWith (
54
+ '[react-markdown] Warning: please pass a string as `children` (not: `1`)'
55
+ )
56
+ console . error = error
57
+ console . warn = warn
58
+ } )
59
+
60
+ test ( 'should warn when passed non-string children (boolean)' , ( ) => {
61
+ const { error, warn} = console
62
+ console . error = jest . fn ( )
63
+ console . warn = jest . fn ( )
64
+ // @ts -ignore runtime
65
+ expect ( renderHTML ( < Markdown children = { false } /> ) ) . toEqual ( '' )
66
+ expect ( console . warn ) . toHaveBeenCalledWith (
67
+ '[react-markdown] Warning: please pass a string as `children` (not: `false`)'
68
+ )
69
+ console . error = error
70
+ console . warn = warn
71
+ } )
72
+
73
+ test ( 'should not warn when passed `null` as children' , ( ) => {
74
+ expect ( renderHTML ( < Markdown children = { null } /> ) ) . toEqual ( '' )
75
+ } )
76
+ test ( 'should not warn when passed `undefined` as children' , ( ) => {
77
+ expect ( renderHTML ( < Markdown children = { undefined } /> ) ) . toEqual ( '' )
78
+ } )
79
+
47
80
test ( 'should warn when passed `allowDangerousHtml`' , ( ) => {
48
81
const warn = console . warn
49
82
console . warn = jest . fn ( )
0 commit comments