Skip to content

Instantly share code, notes, and snippets.

@Munter
Created May 28, 2020 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Munter/8ee82ec1eb59e0ad8415910aa6b787dc to your computer and use it in GitHub Desktop.
Save Munter/8ee82ec1eb59e0ad8415910aa6b787dc to your computer and use it in GitHub Desktop.
Typings for unexpected
declare module "magicpen" {
function magicpen(): magicpen.MagicPen;
namespace magicpen {
interface MagicPen {
/**
* @see https://github.com/sunesimonsen/magicpen#textcontent-stylestring
*/
text(content: string, ...style: Array<string>): this;
/**
* @see https://github.com/sunesimonsen/magicpen#appendpen-appendfunction
*/
append(pen: this): this;
append(fn: (this: this) => void): this;
/**
* @see https://github.com/sunesimonsen/magicpen#cloneformat
*/
clone(): this;
/**
* @see https://github.com/sunesimonsen/magicpen#aliases
*/
space(count: number): this;
bold(content: string): this;
dim(content: string): this;
italic(content: string): this;
underline(content: string): this;
inverse(content: string): this;
hidden(content: string): this;
strikeThrough(content: string): this;
black(content: string): this;
red(content: string): this;
green(content: string): this;
yellow(content: string): this;
blue(content: string): this;
magenta(content: string): this;
cyan(content: string): this;
white(content: string): this;
gray(content: string): this;
bgBlack(content: string): this;
bgRed(content: string): this;
bgGreen(content: string): this;
bgYellow(content: string): this;
bgBlue(content: string): this;
bgMagenta(content: string): this;
bgCyan(content: string): this;
bgWhite(content: string): this;
}
interface MagicPenConstructor {
new (): MagicPen;
prototype: MagicPen;
}
}
export = magicpen;
}
declare module "unexpected" {
import * as magicpen from "magicpen";
namespace unexpected {
interface Expect {
/**
* @see http://unexpected.js.org/api/expect/
*/
<A extends Array<unknown> = []>(subject: unknown, assertionName: string, ...args: A): Promise<
void
>;
/**
* @see http://unexpected.js.org/api/clone/
*/
clone(): this;
/**
* @see http://unexpected.js.org/api/addAssertion/
*/
addAssertion<T, A extends Array<unknown> = []>(
pattern: string,
handler: (expect: Expect, subject: T, ...args: A) => void
): this;
/**
* @see http://unexpected.js.org/api/addType/
*/
addType<T>(typeDefinition: unexpected.TypeDefinition<T>): this;
/**
* @see http://unexpected.js.org/api/fail/
*/
fail<A extends Array<unknown> = []>(format: string, ...args: A): void;
fail<E extends Error>(error: E): void;
/**
* @see http://unexpected.js.org/api/freeze/
*/
freeze(): this;
/**
* @see http://unexpected.js.org/api/use/
*/
use(plugin: unexpected.PluginDefinition): this;
errorMode: "default" | "bubble" | "bubbleThrough" | "nested";
}
interface PluginDefinition {
name?: string;
version?: string;
dependencies?: Array<string>;
installInto(expect: Expect): void;
}
interface TypeDefinition<T> {
name: string;
identify(value: unknown): value is T;
base?: string;
equal?(a: T, b: T, equal: (a: unknown, b: unknown) => boolean): boolean;
inspect?(
value: T,
depth: number,
output: magicpen.MagicPen,
inspect: (value: unknown, depth: number) => magicpen.MagicPen
): void;
}
}
const unexpected: unexpected.Expect;
export = unexpected;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment