Bin
2025-12-17 2b99d77d73ba568beff0a549534017caaad8a6de
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import * as helpers from "../helpers";
 
describe("helpers", () => {
  const originalMaxSafeInteger = Number.MAX_SAFE_INTEGER;
 
  beforeEach(() => {
    // Mock Number.MAX_SAFE_INTEGER to a smaller value for testing purposes as NodeJS supports larger integers than Web.
    Object.defineProperty(Number, "MAX_SAFE_INTEGER", {
      value: 9007199254740991,
    });
  });
 
  afterEach(() => {
    Object.defineProperty(Number, "MAX_SAFE_INTEGER", {
      value: originalMaxSafeInteger,
    });
  });
 
  describe("jsonReviverWithBigInt", () => {
    it("should return the source value if the value is a number and the source is defined and exceeds MAX_SAFE_INTEGER", () => {
      const key = "key";
      const value = 9007199254740992;
      const source = "9007199254740992";
      const context = { source };
 
      const result = helpers.jsonReviverWithBigInt(key, value, context);
      expect(result).toBe(source);
    });
 
    it("should return the source value if the value is a number and the source defined is less than -MAX_SAFE_INTEGER", () => {
      const key = "key";
      const value = -9007199254740992;
      const source = "-9007199254740992";
      const context = { source };
 
      const result = helpers.jsonReviverWithBigInt(key, value, context);
      expect(result).toBe(source);
    });
 
    it("should return the value if the value is a number and the source defined is less than or equal to MAX_SAFE_INTEGER", () => {
      const key = "key";
      const value = 9007199254740991;
      const source = 9007199254740991;
      const context = { source };
 
      const result = helpers.jsonReviverWithBigInt(key, value, context);
      expect(result).toBe(source);
    });
  });
 
  it("should return the value if the value is a number and the source defined is greater than or equal to -MAX_SAFE_INTEGER", () => {
    const key = "key";
    const value = -9007199254740991;
    const source = -9007199254740991;
    const context = { source };
 
    const result = helpers.jsonReviverWithBigInt(key, value, context);
    expect(result).toBe(source);
  });
});