// Type definitions for code 4.0 // Project: https://github.com/hapijs/code // Definitions by: Prashant Tiwari // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /** Generates an assertion object. */ export function expect(value: T | T[], prefix?: string): AssertionChain; /** Makes the test fail with the given message. */ export function fail(message: string): void; /** Returns the total number of assertions created using the expect() method. */ export function count(): number; /** Returns an array of the locations where incomplete assertions were declared or null if no incomplete assertions found. */ export function incomplete(): string[] | null; /** Returns the filename, line number, and column number of where the error was created. */ export function thrownAt(error?: Error): CodeError; /** Configure code. */ export const settings: Settings; export type AssertionChain = Assertion & Expectation; export type Assertion = Grammar & Flags; export type Expectation = Types & Values; export interface Grammar { /** Connecting word. */ a: AssertionChain; /** Connecting word. */ an: AssertionChain; /** Connecting word. */ and: AssertionChain; /** Connecting word. */ at: AssertionChain; /** Connecting word. */ be: AssertionChain; /** Connecting word. */ have: AssertionChain; /** Connecting word. */ in: AssertionChain; /** Connecting word. */ to: AssertionChain; } export interface Flags { /** Inverses the expected result of any assertion */ not: AssertionChain; /** * Requires that inclusion matches appear only once in the provided value. * Used by include(). */ once: AssertionChain; /** * Requires that only the provided elements appear in the provided value. * Used by include(). */ only: AssertionChain; /** * Allows a partial match when asserting inclusion * Used by include(). Defaults to false. */ part: AssertionChain; /** * Performs a comparison using strict equality (===). * Code defaults to deep comparison. Used by equal() and include(). */ shallow: AssertionChain; } export interface Types { /** Asserts that the reference value is an arguments object. */ arguments(): AssertionChain; /** Asserts that the reference value is an Array. */ array(): AssertionChain; /** Asserts that the reference value is a boolean. */ boolean(): AssertionChain; /** Asserts that the reference value is a Buffer. */ buffer(): AssertionChain; /** Asserts that the reference value is a Date. */ date(): AssertionChain; /** Asserts that the reference value is an error. */ error(type?: any, message?: string | RegExp): AssertionChain; /** Asserts that the reference value is a function. */ function(): AssertionChain; /** Asserts that the reference value is a number. */ number(): AssertionChain; /** Asserts that the reference value is a RegExp. */ regexp(): AssertionChain; /** Asserts that the reference value is a string. */ string(): AssertionChain; /** Asserts that the reference value is an object (excluding array, buffer, or other native objects). */ object(): AssertionChain; } export interface Values { /** Asserts that the reference value is true. */ true(): AssertionChain; /** Asserts that the reference value is false. */ false(): AssertionChain; /** Asserts that the reference value is null. */ null(): AssertionChain; /** Asserts that the reference value is undefined. */ undefined(): AssertionChain; /** Asserts that the reference value (a string, array, or object) includes the provided values. */ include(values: string | string[] | T | T[]): AssertionChain; /** Asserts that the reference value (a string, array, or object) includes the provided values. */ includes(values: string | string[] | T | T[]): AssertionChain; /** Asserts that the reference value (a string, array, or object) includes the provided values. */ contain(values: string | string[] | T | T[]): AssertionChain; /** Asserts that the reference value (a string, array, or object) includes the provided values. */ contains(values: string | string[] | T | T[]): AssertionChain; /** Asserts that the reference value (a string) starts with the provided value. */ startWith(value: string): AssertionChain; /** Asserts that the reference value (a string) starts with the provided value. */ startsWith(value: string): AssertionChain; /** Asserts that the reference value (a string) ends with the provided value. */ endWith(value: string): AssertionChain; /** Asserts that the reference value (a string) ends with the provided value. */ endsWith(value: string): AssertionChain; /** Asserts that the reference value exists (not null or undefined). */ exist(): AssertionChain; /** Asserts that the reference value exists (not null or undefined). */ exists(): AssertionChain; /** Asserts that the reference value has a length property equal to zero or an object with no keys. */ empty(): AssertionChain; /** Asserts that the reference value has a length property matching the provided size or an object with the specified number of keys. */ length(size: number): AssertionChain; /** Asserts that the reference value equals the provided value. */ equal(value: T | T[], options?: any): AssertionChain; /** Asserts that the reference value equals the provided value. */ equals(value: T | T[], options?: any): AssertionChain; /** Asserts that the reference value is greater than (>) the provided value. */ above(value: T): AssertionChain; /** Asserts that the reference value is greater than (>) the provided value. */ greaterThan(value: T): AssertionChain; /** Asserts that the reference value is at least (>=) the provided value. */ least(value: T): AssertionChain; /** Asserts that the reference value is at least (>=) the provided value. */ min(value: T): AssertionChain; /** Asserts that the reference value is less than (<) the provided value. */ below(value: T): AssertionChain; /** Asserts that the reference value is less than (<) the provided value. */ lessThan(value: T): AssertionChain; /** Asserts that the reference value is at most (<=) the provided value. */ most(value: T): AssertionChain; /** Asserts that the reference value is at most (<=) the provided value. */ max(value: T): AssertionChain; /** Asserts that the reference value is within (from <= value <= to) the provided values. */ within(from: T, to: T): AssertionChain; /** Asserts that the reference value is within (from <= value <= to) the provided values. */ range(from: T, to: T): AssertionChain; /** Asserts that the reference value is between but not equal (from < value < to) the provided values. */ between(from: T, to: T): AssertionChain; /** Asserts that the reference value is about the provided value within a delta margin of difference. */ about(value: number, delta: number): AssertionChain; /** Asserts that the reference value has the provided instanceof value. */ instanceof(type: any): AssertionChain; /** Asserts that the reference value has the provided instanceof value. */ instanceOf(type: any): AssertionChain; /** Asserts that the reference value's toString() representation matches the provided regular expression. */ match(regex: RegExp): AssertionChain; /** Asserts that the reference value's toString() representation matches the provided regular expression. */ matches(regex: RegExp): AssertionChain; /** Asserts that the Promise reference value rejects with an exception when called */ reject(type?: any, message?: string | RegExp): AssertionChain; /** Asserts that the Promise reference value rejects with an exception when called */ rejects(type?: any, message?: string | RegExp): AssertionChain; /** Asserts that the reference value satisfies the provided validator function. */ satisfy(validator: (value: T) => boolean): AssertionChain; /** Asserts that the reference value satisfies the provided validator function. */ satisfies(validator: (value: T) => boolean): AssertionChain; /** Asserts that the function reference value throws an exception when called. */ throw(type?: any, message?: string | RegExp): AssertionChain; /** Asserts that the function reference value throws an exception when called. */ throws(type?: any, message?: string | RegExp): AssertionChain; } export interface Settings { /** * Truncate long assertion error messages for readability? * Defaults to true. */ truncateMessages?: boolean | undefined; /** * Ignore object prototypes when doing a deep comparison? * Defaults to false. */ comparePrototypes?: boolean | undefined; } export interface CodeError { filename: string; line: string; column: string; }