diff --git a/types/ink-testing-library/index.d.ts b/types/ink-testing-library/index.d.ts new file mode 100644 index 0000000000..bf73d64b3a --- /dev/null +++ b/types/ink-testing-library/index.d.ts @@ -0,0 +1,18 @@ +// Type definitions for ink-testing-library 1.0 +// Project: https://github.com/vadimdemedes/ink-testing-library#readme +// Definitions by: Sam Palmer +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.9 + +import { Component, InkElement } from "ink"; +export interface RenderResponse { + rerender: (tree: InkElement) => void; + unmount: () => void; + stdin: { + write: (data: any) => boolean; + }; + frames: ReadonlyArray; + lastFrame: () => string; +} +export function cleanup(): void; +export function render(tree: InkElement): RenderResponse; diff --git a/types/ink-testing-library/ink-testing-library-tests.tsx b/types/ink-testing-library/ink-testing-library-tests.tsx new file mode 100644 index 0000000000..7cf783a344 --- /dev/null +++ b/types/ink-testing-library/ink-testing-library-tests.tsx @@ -0,0 +1,24 @@ +/** @jsx h */ +import { render, RenderResponse, cleanup } from "ink-testing-library"; +import { Component, h } from "ink"; + +const renderResponse = render( />); // $ExpectType RenderResponse + +renderResponse.frames; // $ExpectType ReadonlyArray + +const rerender = renderResponse.rerender; // $ExpectType (tree: InkElement) => void +rerender( />); // $ExpectType void + +const unmount = renderResponse.unmount; // $ExpectType () => void +unmount(); // $ExpectType void + +const stdin = renderResponse.stdin; // $ExpectType { write: (data: any) => boolean; } +stdin.write(""); // $ExpectType boolean +stdin.write([]); // $ExpectType boolean +stdin.write({}); // $ExpectType boolean + +const lastFrame = renderResponse.lastFrame; // $ExpectType () => string +lastFrame(); // $ExpectType string + +cleanup; // $ExpectType () => void +cleanup(); // $ExpectType void diff --git a/types/ink-testing-library/tsconfig.json b/types/ink-testing-library/tsconfig.json new file mode 100644 index 0000000000..fed5182de7 --- /dev/null +++ b/types/ink-testing-library/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "jsx": "react", + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "allowSyntheticDefaultImports": true, + "strictFunctionTypes": true + }, + "files": [ + "index.d.ts", + "ink-testing-library-tests.tsx" + ] +} diff --git a/types/ink-testing-library/tslint.json b/types/ink-testing-library/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/ink-testing-library/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }