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 17:49:52 +0200 |
commit | cc29542ad87fba6d605e65f468f1943bf8e200cb (patch) | |
tree | 36b5c4ff43481e3b40bde9a01ccc2b8806769cfe /tests.ts | |
parent | 9800339439d7ecffc8aa6e746643b75d4e23ea17 (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" + ); + } +}); |