test(shared): improve test case for toDisplayString (#4337)
This commit is contained in:
parent
42a334e12e
commit
3201224ecb
@ -19,9 +19,46 @@ describe('toDisplayString', () => {
|
|||||||
expect(toDisplayString(obj)).toBe(JSON.stringify(obj, null, 2))
|
expect(toDisplayString(obj)).toBe(JSON.stringify(obj, null, 2))
|
||||||
const arr = [obj]
|
const arr = [obj]
|
||||||
expect(toDisplayString(arr)).toBe(JSON.stringify(arr, null, 2))
|
expect(toDisplayString(arr)).toBe(JSON.stringify(arr, null, 2))
|
||||||
const foo = Object.create(null)
|
|
||||||
foo.bar = 1
|
const objWithToStringOverride = {
|
||||||
expect(toDisplayString(foo)).toBe(JSON.stringify(foo, null, 2))
|
foo: 555,
|
||||||
|
toString() {
|
||||||
|
return 'override'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(toDisplayString(objWithToStringOverride)).toBe('override')
|
||||||
|
|
||||||
|
const objWithNonInvokeableToString = {
|
||||||
|
foo: 555,
|
||||||
|
toString: null
|
||||||
|
}
|
||||||
|
expect(toDisplayString(objWithNonInvokeableToString)).toBe(
|
||||||
|
`{
|
||||||
|
"foo": 555,
|
||||||
|
"toString": null
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
|
||||||
|
// object created from null does not have .toString in its prototype
|
||||||
|
const nullObjectWithoutToString = Object.create(null)
|
||||||
|
nullObjectWithoutToString.bar = 1
|
||||||
|
expect(toDisplayString(nullObjectWithoutToString)).toBe(
|
||||||
|
`{
|
||||||
|
"bar": 1
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
|
||||||
|
// array toString override is ignored
|
||||||
|
const arrWithToStringOverride = [1, 2, 3]
|
||||||
|
arrWithToStringOverride.toString = () =>
|
||||||
|
'override for array is not supported'
|
||||||
|
expect(toDisplayString(arrWithToStringOverride)).toBe(
|
||||||
|
`[
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
]`
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('refs', () => {
|
test('refs', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user