File tree 1 file changed +40
-3
lines changed
packages/shared/__tests__
1 file changed +40
-3
lines changed Original file line number Diff line number Diff line change @@ -19,9 +19,46 @@ describe('toDisplayString', () => {
19
19
expect ( toDisplayString ( obj ) ) . toBe ( JSON . stringify ( obj , null , 2 ) )
20
20
const arr = [ obj ]
21
21
expect ( toDisplayString ( arr ) ) . toBe ( JSON . stringify ( arr , null , 2 ) )
22
- const foo = Object . create ( null )
23
- foo . bar = 1
24
- expect ( toDisplayString ( foo ) ) . toBe ( JSON . stringify ( foo , null , 2 ) )
22
+
23
+ const objWithToStringOverride = {
24
+ foo : 555 ,
25
+ toString ( ) {
26
+ return 'override'
27
+ }
28
+ }
29
+ expect ( toDisplayString ( objWithToStringOverride ) ) . toBe ( 'override' )
30
+
31
+ const objWithNonInvokeableToString = {
32
+ foo : 555 ,
33
+ toString : null
34
+ }
35
+ expect ( toDisplayString ( objWithNonInvokeableToString ) ) . toBe (
36
+ `{
37
+ "foo": 555,
38
+ "toString": null
39
+ }`
40
+ )
41
+
42
+ // object created from null does not have .toString in its prototype
43
+ const nullObjectWithoutToString = Object . create ( null )
44
+ nullObjectWithoutToString . bar = 1
45
+ expect ( toDisplayString ( nullObjectWithoutToString ) ) . toBe (
46
+ `{
47
+ "bar": 1
48
+ }`
49
+ )
50
+
51
+ // array toString override is ignored
52
+ const arrWithToStringOverride = [ 1 , 2 , 3 ]
53
+ arrWithToStringOverride . toString = ( ) =>
54
+ 'override for array is not supported'
55
+ expect ( toDisplayString ( arrWithToStringOverride ) ) . toBe (
56
+ `[
57
+ 1,
58
+ 2,
59
+ 3
60
+ ]`
61
+ )
25
62
} )
26
63
27
64
test ( 'refs' , ( ) => {
You can’t perform that action at this time.
0 commit comments