diff options
| author | Kevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com> | 2018-06-05 01:22:39 -0700 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2018-06-11 11:57:00 +0200 |
| commit | 93654831fe501a4a011610bfc52b2d0fc87eb949 (patch) | |
| tree | 1d3c40fd7db9c3e1dbfd7b27c9bc1e26bc1998de /tests.ts | |
| parent | 4d3e684366395782dfb11acbc05d877121746887 (diff) | |
Improve console and stringify.
Diffstat (limited to 'tests.ts')
| -rw-r--r-- | tests.ts | 71 |
1 files changed, 71 insertions, 0 deletions
@@ -55,3 +55,74 @@ test(async function tests_writeFileSync() { const actual = dec.decode(dataRead); assertEqual("Hello", actual); }); + +test(function tests_console_assert() { + console.assert(true); + + let hasThrown = false; + try { + console.assert(false); + } catch { + hasThrown = true; + } + assertEqual(hasThrown, true); +}); + +test(function tests_console_stringify_circular() { + class Base { + a = 1; + m1() {} + } + + class Extended extends Base { + b = 2; + m2() {} + } + + // tslint:disable-next-line:no-any + const nestedObj: any = { + num: 1, + bool: true, + str: "a", + method() {}, + un: undefined, + nu: null, + arrowFunc: () => {}, + extendedClass: new Extended(), + nFunc: new Function(), + extendedCstr: Extended, + }; + + const circularObj = { + num: 2, + bool: false, + str: "b", + method() {}, + un: undefined, + nu: null, + nested: nestedObj, + emptyObj: {}, + arr: [1, "s", false, null, nestedObj], + baseClass: new Base(), + }; + + nestedObj.o = circularObj; + + try { + console.log(1); + console.log("s"); + console.log(false); + console.log(Symbol(1)); + console.log(null); + console.log(undefined); + console.log(new Extended()); + console.log(function f() {}); + console.log(nestedObj); + console.log(JSON); + console.log(console); + } catch { + throw new Error( + "Expected no crash on circular object" + ); + } +}); |
