diff options
| author | Kitson Kelly <me@kitsonkelly.com> | 2019-01-16 13:57:40 +1100 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2019-01-15 21:57:40 -0500 |
| commit | 7cb7b24537cd3771f8d2a02bdae9bffc9c7fcbb8 (patch) | |
| tree | 2b1697f517124515ae6d9951a9f66ebc2caf3568 /testing/test.ts | |
| parent | 8dd76af9ab7caa6f92b8a89a7adc61504dc7d277 (diff) | |
Improve assert (denoland/deno_std#124)
Original: https://github.com/denoland/deno_std/commit/9a3eb207dcd1d032a3c3f7e60f8ee9c5e793f022
Diffstat (limited to 'testing/test.ts')
| -rw-r--r-- | testing/test.ts | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/testing/test.ts b/testing/test.ts index 7012a6e47..34b2762b4 100644 --- a/testing/test.ts +++ b/testing/test.ts @@ -28,6 +28,7 @@ test(function testingAssertEqual() { const a = Object.create(null); a.b = "foo"; assertEqual(a, a); + assert(assert.equal === assertEqual); }); test(function testingAssertEqualActualUncoercable() { @@ -55,3 +56,108 @@ test(function testingAssertEqualExpectedUncoercable() { } assert(didThrow); }); + +test(function testingAssertStrictEqual() { + const a = {}; + const b = a; + assert.strictEqual(a, b); +}); + +test(function testingAssertNotStrictEqual() { + let didThrow = false; + const a = {}; + const b = {}; + try { + assert.strictEqual(a, b); + } catch (e) { + assert(e.message === "actual: [object Object] expected: [object Object]"); + didThrow = true; + } + assert(didThrow); +}); + +test(function testingDoesThrow() { + let count = 0; + assert.throws(() => { + count++; + throw new Error(); + }); + assert(count === 1); +}); + +test(function testingDoesNotThrow() { + let count = 0; + let didThrow = false; + try { + assert.throws(() => { + count++; + console.log("Hello world"); + }); + } catch (e) { + assert(e.message === "Expected function to throw."); + didThrow = true; + } + assert(count === 1); + assert(didThrow); +}); + +test(function testingThrowsErrorType() { + let count = 0; + assert.throws(() => { + count++; + throw new TypeError(); + }, TypeError); + assert(count === 1); +}); + +test(function testingThrowsNotErrorType() { + let count = 0; + let didThrow = false; + try { + assert.throws(() => { + count++; + throw new TypeError(); + }, RangeError); + } catch (e) { + assert(e.message === `Expected error to be instance of "RangeError".`); + didThrow = true; + } + assert(count === 1); + assert(didThrow); +}); + +test(function testingThrowsMsgIncludes() { + let count = 0; + assert.throws( + () => { + count++; + throw new TypeError("Hello world!"); + }, + TypeError, + "world" + ); + assert(count === 1); +}); + +test(function testingThrowsMsgNotIncludes() { + let count = 0; + let didThrow = false; + try { + assert.throws( + () => { + count++; + throw new TypeError("Hello world!"); + }, + TypeError, + "foobar" + ); + } catch (e) { + assert( + e.message === + `Expected error message to include "foobar", but got "Hello world!".` + ); + didThrow = true; + } + assert(count === 1); + assert(didThrow); +}); |
