From 2ed977bc7e7b0102e48a8e839fee1b03751d2db9 Mon Sep 17 00:00:00 2001 From: Adam Zerella Date: Mon, 29 Apr 2019 17:08:13 +1000 Subject: [PATCH] Added type def for proclaim (#35041) --- types/proclaim/index.d.ts | 270 +++++++++++++++++++++++++++++++ types/proclaim/proclaim-tests.ts | 54 +++++++ types/proclaim/tsconfig.json | 23 +++ types/proclaim/tslint.json | 1 + 4 files changed, 348 insertions(+) create mode 100644 types/proclaim/index.d.ts create mode 100644 types/proclaim/proclaim-tests.ts create mode 100644 types/proclaim/tsconfig.json create mode 100644 types/proclaim/tslint.json diff --git a/types/proclaim/index.d.ts b/types/proclaim/index.d.ts new file mode 100644 index 0000000000..bb2b30c3f1 --- /dev/null +++ b/types/proclaim/index.d.ts @@ -0,0 +1,270 @@ +// Type definitions for proclaim 3.6 +// Project: https://github.com/rowanmanning/proclaim +// Definitions by: Adam Zerella +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +export {}; + +interface AssertionError { + msg: string; + actual: any; + expected: any; + operator: string; + stackStartFunction: any; +} + +/** + * Throw an assertion error. + */ +export function fail(actual: any, expected: any, msg: string, operator: string): AssertionError; + +/** + * Assert that value is truthy. + */ +export function ok(value: any, msg: string): AssertionError|void; + +/** + * Assert that value is falsy. + */ +export function notOk(value: any, msg: string): AssertionError|void; + +/** + * Assert that actual == expected. + */ +export function equal(actual: any, expected: any, msg: string): AssertionError|void; + +/** + * Assert that actual != expected. + */ +export function notEqual(actual: any, expected: any, msg: string): AssertionError|void; + +/** + * Assert that actual === expected. + */ +export function strictEqual(actual: any, expected: any, msg: string): AssertionError|void; + +/** + * Assert that actual !== expected. + */ +export function notStrictEqual(actual: any, expected: any, msg: string): AssertionError|void; + +/** + * Assert that actual is deeply equal to expected. + */ +export function deepEqual(actual: any, expected: any, msg: string): AssertionError|void; + +/** + * Assert that actual is not deeply equal to expected. + */ +export function notDeepEqual(actual: any, expected: any, msg: string): AssertionError|void; + +/** + * Assert that actual is deeply equal to expected, as determined by the strict equality operator ===. + */ +export function deepStrictEqual(actual: any, expected: any, msg: string): AssertionError|void; + +/** + * Assert that actual is not deeply equal to expected, as determined by the strict not equal operator !==. + */ +export function notDeepStrictEqual(actual: any, expected: any, msg: string): AssertionError|void; + +/** + * Assert that fn throws an error. + */ +export function throws(fn: () => void, expected: any, msg: string): AssertionError|void; + +/** + * Assert that fn does not throw an error. + */ +export function doesNotThrow(fn: () => void, expected: any, msg: string): AssertionError|void; + +/** + * Assert that typeof actual === expected. + */ +export function isTypeOf(actual: any, expected: any, msg: string): AssertionError|void; + +/** + * Assert that typeof actual !== expected. + */ +export function isNotTypeOf(actual: any, expected: any, msg: string): AssertionError|void; + +/** + * Assert that actual instanceof expected. + */ +export function isInstanceOf(actual: any, expected: any, msg: string): AssertionError|void; + +/** + * Assert that !(actual instanceof expected). + */ +export function isNotInstanceOf(actual: any, expected: any, msg: string): AssertionError|void; + +/** + * Assert that value is an array. + */ +export function isArray(value: any, msg: string): AssertionError|void; + +/** + * Assert that value is not an array. + */ +export function isNotArray(value: any, msg: string): AssertionError|void; + +/** + * Assert that value is a boolean. + */ +export function isBoolean(value: any, msg: string): AssertionError|void; + +/** + * Assert that value is not a boolean. + */ +export function isNotBoolean(value: any, msg: string): AssertionError|void; + +/** + * Assert that value === true. + */ +export function isTrue(value: any, msg: string): AssertionError|void; + +/** + * Assert that value === false. + */ +export function isFalse(value: any, msg: string): AssertionError|void; + +/** + * Assert that value is a function. + */ +export function isFunction(value: any, msg: string): AssertionError|void; + +/** + * Assert that value is not a function. + */ +export function isNotFunction(value: any, msg: string): AssertionError|void; + +/** + * Assert that value is NaN. + */ +export function isNaN(value: any, msg: string): AssertionError|void; + +/** + * Assert that value is not NaN. + */ +export function isNotNaN(value: any, msg: string): AssertionError|void; + +/** + * Assert that value === null. + */ +export function isNull(value: any, msg: string): AssertionError|void; + +/** + * Assert that value !== null. + */ +export function isNotNull(value: any, msg: string): AssertionError|void; + +/** + * Assert that value is a number. + */ +export function isNumber(value: any, msg: string): AssertionError|void; + +/** + * Assert that value is not a number. + */ +export function isNotNumber(value: any, msg: string): AssertionError|void; + +/** + * Assert that value is an object. + */ +export function isObject(value: any, msg: string): AssertionError|void; + +/** + * Assert that value is not an object. + */ +export function isNotObject(value: any, msg: string): AssertionError|void; + +/** + * Assert that value is a string. + */ +export function isString(value: any, msg: string): AssertionError|void; + +/** + * Assert that value is not a string. + */ +export function isNotString(value: any, msg: string): AssertionError|void; + +/** + * Assert that value === undefined. + */ +export function isUndefined(value: any, msg: string): AssertionError|void; + +/** + * Assert that value !== undefined. + */ +export function isDefined(value: any, msg: string): AssertionError|void; + +/** + * Assert that actual matches the RegExp in expected. + */ +export function match(actual: any, expected: any, msg: string): AssertionError|void; + +/** + * Assert that actual does not match the RegExp in expected. + */ +export function notMatch(actual: any, expected: any, msg: string): AssertionError|void; + +/** + * Assert that haystack contains needle. + */ +export function include(haystack: any, needle: any, msg: string): AssertionError|void; + +/** + * Assert that haystack does not contain needle. + */ +export function doesNotInclude(haystack: any, needle: any, msg: string): AssertionError|void; + +/** + * Assert that value.length === expected. + */ +export function lengthEquals(actual: any, expected: any, msg: string): AssertionError|void; + +/** + * Assert that actual < expected. + */ +export function lessThan(actual: any, expected: any, msg: string): AssertionError|void; + +/** + * Assert that actual <= expected. + */ +export function lessThanOrEqual(actual: any, expected: any, msg: string): AssertionError|void; + +/** + * Assert that actual > expected. + */ +export function greaterThan(actual: any, expected: any, msg: string): AssertionError|void; + +/** + * Assert that actual >= expected. + */ +export function greaterThanOrEqual(actual: any, expected: any, msg: string): AssertionError|void; + +/** + * Assert that fn.length === expected. + */ +export function arity(fn: () => void, expected: any, msg: string): AssertionError|void; + +/** + * Assert that Math.abs(actual - expected) < (0.5 * Math.pow(10, -precision)). + */ +export function almostEqual(actual: any, expected: any, precision: number, msg: string): AssertionError|void; + +/** + * Assert that obj[property] is not enumerable. + */ +export function isNotEnumerable(object: object, property: any, msg: string): AssertionError|void; + +/** + * Assert that obj[property] is enumerable. + */ +export function isEnumerable(object: object, property: any, msg: string): AssertionError|void; + +/** + * Assert that fn.name === expected. + */ +export function hasName(fn: () => void, expected: any, msg: string): AssertionError|void; diff --git a/types/proclaim/proclaim-tests.ts b/types/proclaim/proclaim-tests.ts new file mode 100644 index 0000000000..43605fa852 --- /dev/null +++ b/types/proclaim/proclaim-tests.ts @@ -0,0 +1,54 @@ +import proclaim = require('proclaim'); + +proclaim.fail('foo', 'bar', 'Foo equals bar', '==='); +proclaim.ok(5, '5 equals true'); +proclaim.notOk(5, '5 equals false'); +proclaim.equal('abc', 'bca', 'Foo equals bar'); +proclaim.notEqual('abc', 'bca', 'Foo equals bar'); +proclaim.strictEqual('abc', 'bca', 'Foo equals bar'); +proclaim.notStrictEqual('abc', 'bca', 'Foo equals bar'); +proclaim.deepEqual('abc', 'bca', 'Foo equals bar'); +proclaim.notDeepEqual('abc', 'bca', 'Foo equals bar'); +proclaim.deepStrictEqual('abc', 'bca', 'Foo equals bar'); +proclaim.notDeepStrictEqual('abc', 'bca', 'Foo equals bar'); +proclaim.throws(() => {}, {}, 'throws error'); +proclaim.doesNotThrow(() => {}, {}, 'throws error'); +proclaim.isTypeOf('same type', 'same type', 'values match'); +proclaim.isNotTypeOf('same type', 'same type', 'values dont match'); +proclaim.isInstanceOf('same instance', 'same instance', 'instance match'); +proclaim.isNotInstanceOf('same instance', 'same instance', 'instance dont match'); +proclaim.isArray([], 'is array'); +proclaim.isNotArray([], 'is array'); +proclaim.isBoolean(true, 'is bool'); +proclaim.isNotBoolean(true, 'is bool'); +proclaim.isTrue(true, 'is true'); +proclaim.isFalse(false, 'is true'); +proclaim.isFunction('value here', 'value was a thing'); +proclaim.isNotFunction('value here', 'value was a thing'); +proclaim.isNaN('value here', 'value was a thing'); +proclaim.isNotNaN('value here', 'value was a thing'); +proclaim.isNull('value here', 'value was a thing'); +proclaim.isNotNull('value here', 'value was a thing'); +proclaim.isNumber('value here', 'value was a thing'); +proclaim.isNotNumber('value here', 'value was a thing'); +proclaim.isObject('value here', 'value was a thing'); +proclaim.isNotNull('value here', 'value was a thing'); +proclaim.isNotObject('value here', 'value was a thing'); +proclaim.isString('value here', 'value was a thing'); +proclaim.isNotString('value here', 'value was a thing'); +proclaim.isUndefined('value here', 'value was a thing'); +proclaim.isDefined('value here', 'value was a thing'); +proclaim.match('a', 'a', 'match'); +proclaim.notMatch('a', 'b', 'no match'); +proclaim.include([1, 2, 3], 5, 'no match'); +proclaim.doesNotInclude([1, 2, 3], 5, 'no match'); +proclaim.lengthEquals([1, 2, 3], 3, 'length equals'); +proclaim.lessThan(5, 10, 'true'); +proclaim.lessThanOrEqual(5, 10, 'true'); +proclaim.greaterThan(5, 10, 'false'); +proclaim.greaterThanOrEqual(5, 10, 'false'); +proclaim.arity(() => {}, {}, 'no fn length'); +proclaim.almostEqual(5, 10, 3, 'not almost equal'); +proclaim.isNotEnumerable({}, {}, 'true'); +proclaim.isEnumerable({}, {}, 'true'); +proclaim.hasName(() => {}, 'name here', 'false'); diff --git a/types/proclaim/tsconfig.json b/types/proclaim/tsconfig.json new file mode 100644 index 0000000000..a86e36f08b --- /dev/null +++ b/types/proclaim/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "proclaim-tests.ts" + ] +} \ No newline at end of file diff --git a/types/proclaim/tslint.json b/types/proclaim/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/proclaim/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }