diff --git a/code/code-tests.ts b/code/code-tests.ts index ea956c6c2c..f84d2c852d 100644 --- a/code/code-tests.ts +++ b/code/code-tests.ts @@ -31,7 +31,7 @@ expect(err).to.be.an.error(Error); expect(err).to.be.an.error("Oops an error occured."); expect(err).to.be.an.error(Error, /occured/); -expect(function () { }).to.be.a.function(); +expect(function () { return; }).to.be.a.function(); expect(123).to.be.a.number(); @@ -147,7 +147,7 @@ fail("This should not occur"); expect(count()).to.be.a.number(); -expect(incomplete()).to.be.null().and.not.be.an.array(); +expect(incomplete() as null).to.be.null().and.not.be.an.array(); const error = thrownAt(new Error("oops")); expect(error).to.not.be.undefined(); diff --git a/code/index.d.ts b/code/index.d.ts index 174215f5d8..50c58d3a24 100644 --- a/code/index.d.ts +++ b/code/index.d.ts @@ -1,20 +1,22 @@ -// Type definitions for code 4.0.0 +// 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; +declare function expect(value: T | T[], prefix?: string): AssertionChain; /** Makes the test fail with the given message. */ -export function fail(message: string): void; +declare function fail(message: string): void; /** Returns the total number of assertions created using the expect() method. */ -export function count(): number; +declare function count(): number; /** Returns an array of the locations where incomplete assertions were declared or null if no incomplete assertions found. */ -export function incomplete(): Array | null; +declare function incomplete(): Array | null; /** Returns the filename, line number, and column number of where the error was created. */ -export function thrownAt(error?: Error): CodeError; +declare function thrownAt(error?: Error): CodeError; /** Configure code. */ -export const settings: Settings; +declare const settings: Settings; + +export { expect, fail, count, incomplete, thrownAt, settings }; type AssertionChain = Assertion & Expectation; @@ -165,7 +167,9 @@ interface Values { /** 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: Object, message: string | RegExp): AssertionChain; + throw(type?: Object, message?: string | RegExp): AssertionChain; + /** Asserts that the function reference value throws an exception when called. */ + throws(type?: Object, message?: string | RegExp): AssertionChain; } interface Settings { diff --git a/code/tslint.json b/code/tslint.json new file mode 100644 index 0000000000..192203ab54 --- /dev/null +++ b/code/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "../tslint.json" +} \ No newline at end of file