|
| 1 | +/** |
| 2 | + * Copyright (c) "Neo4j" |
| 3 | + * Neo4j Sweden AB [http://neo4j.com] |
| 4 | + * |
| 5 | + * This file is part of Neo4j. |
| 6 | + * |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +import { json, newError } from '../src' |
| 21 | +import { createBrokenObject } from '../src/internal/object-util' |
| 22 | + |
| 23 | +describe('json', () => { |
| 24 | + describe('.stringify', () => { |
| 25 | + it('should handle objects created with createBrokenObject', () => { |
| 26 | + const reason = newError('some error') |
| 27 | + const broken = createBrokenObject(reason, { }) |
| 28 | + |
| 29 | + expect(json.stringify(broken)).toMatchSnapshot() |
| 30 | + }) |
| 31 | + |
| 32 | + it('should handle objects created with createBrokenObject in list', () => { |
| 33 | + const reason = newError('some error') |
| 34 | + const broken = createBrokenObject(reason, { }) |
| 35 | + |
| 36 | + expect(json.stringify([broken])).toMatchSnapshot() |
| 37 | + }) |
| 38 | + |
| 39 | + it('should handle objects created with createBrokenObject inside other object', () => { |
| 40 | + const reason = newError('some error') |
| 41 | + const broken = createBrokenObject(reason, { }) |
| 42 | + |
| 43 | + expect(json.stringify({ |
| 44 | + number: 1, |
| 45 | + broken |
| 46 | + })).toMatchSnapshot() |
| 47 | + }) |
| 48 | + |
| 49 | + it('should handle BigInt', () => { |
| 50 | + const bigint = BigInt(42) |
| 51 | + |
| 52 | + expect(json.stringify(bigint)).toMatchSnapshot() |
| 53 | + }) |
| 54 | + |
| 55 | + it('should handle BigInt in a list', () => { |
| 56 | + const bigintList = [BigInt(42), BigInt(-24)] |
| 57 | + |
| 58 | + expect(json.stringify(bigintList)).toMatchSnapshot() |
| 59 | + }) |
| 60 | + |
| 61 | + it('should handle BigInt in a object', () => { |
| 62 | + const bigintInObject = { |
| 63 | + theResponse: BigInt(42) |
| 64 | + } |
| 65 | + |
| 66 | + expect(json.stringify(bigintInObject)).toMatchSnapshot() |
| 67 | + }) |
| 68 | + }) |
| 69 | +}) |
0 commit comments