Files
DefinitelyTyped/types/assert/assert-tests.ts
Nathan Shively-Sanders dd38d16a14 Fix node and assert tests for TS 5.0 (#64007)
TS 5.0's type guards return literal types in more cases than before,
which changes the behaviour of many assert functions.
2023-01-23 09:44:30 -08:00

72 lines
1.2 KiB
TypeScript

import * as assert from 'assert';
assert(true, "it's working");
assert.ok(true, 'inner functions work as well');
assert.throws(() => {});
assert.throws(() => {}, /Regex test/);
assert.throws(
() => {},
() => {},
'works wonderfully',
);
assert['fail'](true, true, 'works like a charm');
{
const a = null as any;
assert.ifError(a);
a; // $ExpectType null | undefined
}
{
const a = true as boolean;
assert(a);
a; // $ExpectType true
}
{
const a = 13 as number | null | undefined;
assert(a);
a; // $ExpectType number
}
{
const a = true as boolean;
assert.ok(a);
a; // $ExpectType true
}
{
const a = 13 as number | null | undefined;
assert.ok(a);
a; // $ExpectType number
}
{
const a = 'test' as any;
assert.strictEqual(a, 'test');
a; // $ExpectType string || "test"
}
{
const a = 'test' as any;
assert.strict.equal(a, 'test');
a; // $ExpectType string || "test"
}
{
const a = { b: 2 } as any;
assert.deepStrictEqual(a, { b: 2 });
a; // $ExpectType { b: number; }
}
{
const a = { b: 2 } as any;
assert.strict.deepEqual(a, { b: 2 });
a; // $ExpectType { b: number; }
}
assert.fail(); // $ExpectType never