@@ -3,39 +3,48 @@ import formatPropValue from './formatPropValue';
33import parseReactElement from './../parser/parseReactElement' ;
44import formatTreeNode from './formatTreeNode' ;
55import formatComplexDataStructure from './formatComplexDataStructure' ;
6+
67jest . mock ( './../parser/parseReactElement' ) ;
8+
79jest . mock ( './formatTreeNode' , ( ) =>
810 jest . fn ( ) . mockReturnValue ( '<MockedFormatTreeNodeResult />' )
911) ;
12+
1013jest . mock ( './formatComplexDataStructure' , ( ) =>
1114 jest . fn ( ) . mockReturnValue ( '*Mocked formatComplexDataStructure result*' )
1215) ;
16+
1317describe ( 'formatPropValue' , ( ) => {
1418 beforeEach ( ( ) => {
1519 jest . clearAllMocks ( ) ;
1620 } ) ;
21+
1722 it ( 'should format an integer prop value' , ( ) => {
1823 expect ( formatPropValue ( 42 , false , 0 , { } ) ) . toBe ( '{42}' ) ;
1924 } ) ;
25+
2026 it ( 'should escape double quote on prop value of string type' , ( ) => {
2127 expect ( formatPropValue ( 'Hello "Jonh"!' , false , 0 , { } ) ) . toBe (
2228 '"Hello "Jonh"!"'
2329 ) ;
2430 } ) ;
31+
2532 it ( 'should format a symbol prop value' , ( ) => {
2633 expect ( formatPropValue ( Symbol ( 'Foo' ) , false , 0 , { } ) ) . toBe (
2734 "{Symbol('Foo')}"
2835 ) ;
2936 // eslint-disable-next-line symbol-description
3037 expect ( formatPropValue ( Symbol ( ) , false , 0 , { } ) ) . toBe ( '{Symbol()}' ) ;
3138 } ) ;
39+
3240 it ( 'should replace a function prop value by a an empty generic function by default' , ( ) => {
3341 const doThings = ( a ) => a * 2 ;
3442
3543 expect ( formatPropValue ( doThings , false , 0 , { } ) ) . toBe (
3644 '{function noRefCheck() {}}'
3745 ) ;
3846 } ) ;
47+
3948 it ( 'should show the function prop value implementation if "showFunctions" option is true' , ( ) => {
4049 const doThings = ( a ) => a * 2 ;
4150
@@ -45,11 +54,13 @@ describe('formatPropValue', () => {
4554 } )
4655 ) . toBe ( '{function doThings(a) {return a * 2;}}' ) ;
4756 } ) ;
57+
4858 it ( 'should format the function prop value with the "functionValue" option' , ( ) => {
4959 const doThings = ( a ) => a * 2 ;
5060
5161 const functionValue = ( fn ) => {
5262 expect ( fn ) . toBe ( doThings ) ;
63+
5364 return 'function Myfunction() {}' ;
5465 } ;
5566
@@ -66,23 +77,27 @@ describe('formatPropValue', () => {
6677 } )
6778 ) . toBe ( '{function Myfunction() {}}' ) ;
6879 } ) ;
80+
6981 it ( 'should parse and format a react element prop value' , ( ) => {
7082 expect ( formatPropValue ( < div /> , false , 0 , { } ) ) . toBe (
7183 '{<MockedFormatTreeNodeResult />}'
7284 ) ;
7385 expect ( parseReactElement ) . toHaveBeenCalledTimes ( 1 ) ;
7486 expect ( formatTreeNode ) . toHaveBeenCalledTimes ( 1 ) ;
7587 } ) ;
88+
7689 it ( 'should format a date prop value' , ( ) => {
7790 expect (
7891 formatPropValue ( new Date ( '2017-01-01T11:00:00.000Z' ) , false , 0 , { } )
7992 ) . toBe ( '{new Date("2017-01-01T11:00:00.000Z")}' ) ;
8093 } ) ;
94+
8195 it ( 'should format an invalid date prop value' , ( ) => {
8296 expect ( formatPropValue ( new Date ( NaN ) , false , 0 , { } ) ) . toBe (
8397 '{new Date(NaN)}'
8498 ) ;
8599 } ) ;
100+
86101 it ( 'should format an object prop value' , ( ) => {
87102 expect (
88103 formatPropValue (
@@ -96,22 +111,27 @@ describe('formatPropValue', () => {
96111 ) . toBe ( '{*Mocked formatComplexDataStructure result*}' ) ;
97112 expect ( formatComplexDataStructure ) . toHaveBeenCalledTimes ( 1 ) ;
98113 } ) ;
114+
99115 it ( 'should format an array prop value' , ( ) => {
100116 expect ( formatPropValue ( [ 'a' , 'b' , 'c' ] , false , 0 , { } ) ) . toBe (
101117 '{*Mocked formatComplexDataStructure result*}'
102118 ) ;
103119 expect ( formatComplexDataStructure ) . toHaveBeenCalledTimes ( 1 ) ;
104120 } ) ;
121+
105122 it ( 'should format a boolean prop value' , ( ) => {
106123 expect ( formatPropValue ( true , false , 0 , { } ) ) . toBe ( '{true}' ) ;
107124 expect ( formatPropValue ( false , false , 0 , { } ) ) . toBe ( '{false}' ) ;
108125 } ) ;
126+
109127 it ( 'should format null prop value' , ( ) => {
110128 expect ( formatPropValue ( null , false , 0 , { } ) ) . toBe ( '{null}' ) ;
111129 } ) ;
130+
112131 it ( 'should format undefined prop value' , ( ) => {
113132 expect ( formatPropValue ( undefined , false , 0 , { } ) ) . toBe ( '{undefined}' ) ;
114133 } ) ;
134+
115135 it ( 'should call the ".toString()" method on object instance prop value' , ( ) => {
116136 expect ( formatPropValue ( new Set ( [ 'a' , 'b' , 42 ] ) , false , 0 , { } ) ) . toBe (
117137 '{[object Set]}'
0 commit comments