|
31 | 31 | if (!threw) { |
32 | 32 | throw new Error('Global assert(false, message) must throw'); |
33 | 33 | } |
| 34 | + |
| 35 | +// assert.ok |
| 36 | +if (typeof assert.ok !== 'function') { |
| 37 | + throw new Error('Expected assert.ok to be a function'); |
| 38 | +} |
| 39 | +assert.ok(true); |
| 40 | +threw = false; |
| 41 | +try { assert.ok(false); } catch { threw = true; } |
| 42 | +if (!threw) throw new Error('assert.ok(false) must throw'); |
| 43 | + |
| 44 | +// assert.strictEqual |
| 45 | +if (typeof assert.strictEqual !== 'function') { |
| 46 | + throw new Error('Expected assert.strictEqual to be a function'); |
| 47 | +} |
| 48 | +assert.strictEqual(1, 1); |
| 49 | +assert.strictEqual('a', 'a'); |
| 50 | +assert.strictEqual(NaN, NaN); // uses Object.is semantics |
| 51 | +threw = false; |
| 52 | +try { assert.strictEqual(1, 2); } catch { threw = true; } |
| 53 | +if (!threw) throw new Error('assert.strictEqual(1, 2) must throw'); |
| 54 | + |
| 55 | +// assert.notStrictEqual |
| 56 | +if (typeof assert.notStrictEqual !== 'function') { |
| 57 | + throw new Error('Expected assert.notStrictEqual to be a function'); |
| 58 | +} |
| 59 | +assert.notStrictEqual(1, 2); |
| 60 | +assert.notStrictEqual('a', 'b'); |
| 61 | +threw = false; |
| 62 | +try { assert.notStrictEqual(1, 1); } catch { threw = true; } |
| 63 | +if (!threw) throw new Error('assert.notStrictEqual(1, 1) must throw'); |
| 64 | + |
| 65 | +// assert.deepStrictEqual |
| 66 | +if (typeof assert.deepStrictEqual !== 'function') { |
| 67 | + throw new Error('Expected assert.deepStrictEqual to be a function'); |
| 68 | +} |
| 69 | +assert.deepStrictEqual({ a: 1 }, { a: 1 }); |
| 70 | +assert.deepStrictEqual([1, 2, 3], [1, 2, 3]); |
| 71 | +threw = false; |
| 72 | +try { assert.deepStrictEqual({ a: 1 }, { a: 2 }); } catch { threw = true; } |
| 73 | +if (!threw) throw new Error('assert.deepStrictEqual({ a: 1 }, { a: 2 }) must throw'); |
| 74 | + |
| 75 | +// assert.throws |
| 76 | +if (typeof assert.throws !== 'function') { |
| 77 | + throw new Error('Expected assert.throws to be a function'); |
| 78 | +} |
| 79 | +assert.throws(() => { throw new Error('oops'); }, /oops/); |
| 80 | +assert.throws(() => { throw new TypeError('bad'); }, TypeError); |
| 81 | +threw = false; |
| 82 | +try { assert.throws(() => { /* does not throw */ }); } catch { threw = true; } |
| 83 | +if (!threw) throw new Error('assert.throws must throw when fn does not throw'); |
0 commit comments