|
1 | 1 | import stringify from "../src"; |
2 | 2 |
|
| 3 | +test("empty object", () => { |
| 4 | + expect(stringify({})).toEqual("{}"); |
| 5 | +}); |
| 6 | + |
3 | 7 | test("simple object", () => { |
4 | 8 | const obj = { c: 6, b: [4, 5], a: 3, z: null }; |
5 | 9 | expect(stringify(obj)).toEqual('{"a":3,"b":[4,5],"c":6,"z":null}'); |
@@ -30,7 +34,38 @@ test("object with empty string", () => { |
30 | 34 | expect(stringify(obj)).toEqual('{"a":3,"z":""}'); |
31 | 35 | }); |
32 | 36 |
|
| 37 | +test("object with Symbol", () => { |
| 38 | + const obj = { a: 12, z: Symbol("") }; |
| 39 | + expect(stringify(obj)).toEqual('{"a":12}'); |
| 40 | +}); |
| 41 | + |
| 42 | +test("non-enumerable properties", () => { |
| 43 | + const obj = Object.create(null, { |
| 44 | + x: { value: "x", enumerable: false }, |
| 45 | + y: { value: "y", enumerable: true }, |
| 46 | + }); |
| 47 | + expect(stringify(obj)).toEqual('{"y":"y"}'); |
| 48 | +}); |
| 49 | + |
33 | 50 | test("array with empty string", () => { |
34 | 51 | const obj = [4, "", 6]; |
35 | 52 | expect(stringify(obj)).toEqual('[4,"",6]'); |
36 | 53 | }); |
| 54 | + |
| 55 | +test("simple function", () => { |
| 56 | + const obj = () => { |
| 57 | + // empty |
| 58 | + }; |
| 59 | + expect(stringify(obj)).toEqual(undefined); |
| 60 | +}); |
| 61 | + |
| 62 | +test("standard data structures", () => { |
| 63 | + expect( |
| 64 | + stringify([ |
| 65 | + new Set([1]), |
| 66 | + new Map([[1, 2]]), |
| 67 | + new WeakSet([{ a: 1 }]), |
| 68 | + new WeakMap([[{ a: 1 }, 2]]), |
| 69 | + ]) |
| 70 | + ).toEqual("[{},{},{},{}]"); |
| 71 | +}); |
0 commit comments