diff --git a/types/cavy/cavy-tests.tsx b/types/cavy/cavy-tests.tsx new file mode 100644 index 0000000000..e33d0366a7 --- /dev/null +++ b/types/cavy/cavy-tests.tsx @@ -0,0 +1,40 @@ +import * as React from 'react'; +import { TextInput, View, Text } from 'react-native'; + +import { hook, TestScope, WithTestHook, Tester } from 'cavy'; + +type Props = WithTestHook<{ + foo: string; +}>; + +class SampleComponent extends React.Component { + render() { + return ( + + {this.props.foo} + + + ); + } +} + +const HookedSampleComponent = hook(SampleComponent); // $ExpectType ComponentClass<{ foo: string; }, any> + +function sampleSpec(spec: TestScope) { + spec.describe('it has a name and callback', () => { + spec.it('it has a name and callback', async () => { + spec.component.reRender(); // $ExpectType void + spec.component.clearAsync(); // $ExpectType Promise + spec.findComponent('View.Sample'); // $ExpectType Promise> + spec.press('View.Sample'); // $ExpectType Promise + spec.fillIn('Input.Sample', "hello world"); // $ExpectType Promise + spec.pause(1000); // $ExpectType Promise + spec.exists('View.Sample'); // $ExpectType Promise + spec.notExists('View.MissingSample'); // $ExpectType Promise + }); + }); +} + + + +; diff --git a/types/cavy/index.d.ts b/types/cavy/index.d.ts new file mode 100644 index 0000000000..5e74edfe48 --- /dev/null +++ b/types/cavy/index.d.ts @@ -0,0 +1,40 @@ +// Type definitions for cavy 0.6 +// Project: https://github.com/pixielabs/cavy +// Definitions by: Tyler Hoffman +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.0 + +import * as React from 'react'; + +export {}; + +type RefCallback = (element: React.ReactNode | null) => void; + +export type TestHookGenerator = (label: string, callback?: RefCallback) => RefCallback; + +export type WithTestHook = T & { generateTestHook: TestHookGenerator }; + +export function hook(component: React.ComponentClass>): React.ComponentClass; + +export interface TesterProps { + specs: Array<(spec: TestScope) => void>; + waitTime: number; + sendReport?: boolean; +} + +export class Tester extends React.Component { + reRender(): void; + clearAsync(): Promise; +} + +export class TestScope { + component: Tester; + findComponent(identifier: string): Promise; + describe(label: string, fn: () => void): void; + it(label: string, fn: () => void): void; + press(identifier: string): Promise; + fillIn(identifier: string, str: string): Promise; + pause(time: number): Promise; + exists(identifier: string): Promise; + notExists(identifier: string): Promise; +} diff --git a/types/cavy/tsconfig.json b/types/cavy/tsconfig.json new file mode 100644 index 0000000000..4b78de6410 --- /dev/null +++ b/types/cavy/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "jsx": "react", + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "cavy-tests.tsx" + ] +} \ No newline at end of file diff --git a/types/cavy/tslint.json b/types/cavy/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/cavy/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }