mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-10 12:10:18 +00:00
Merge pull request #33348 from tyler-hoffman/feature/cavy
Add cavy types
This commit is contained in:
40
types/cavy/cavy-tests.tsx
Normal file
40
types/cavy/cavy-tests.tsx
Normal file
@@ -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<Props> {
|
||||
render() {
|
||||
return (
|
||||
<View ref={this.props.generateTestHook('View.Sample')}>
|
||||
<Text>{this.props.foo}</Text>
|
||||
<TextInput ref={this.props.generateTestHook("Input.Sample")} />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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<void>
|
||||
spec.findComponent('View.Sample'); // $ExpectType Promise<Component<{}, {}, any>>
|
||||
spec.press('View.Sample'); // $ExpectType Promise<void>
|
||||
spec.fillIn('Input.Sample', "hello world"); // $ExpectType Promise<void>
|
||||
spec.pause(1000); // $ExpectType Promise<void>
|
||||
spec.exists('View.Sample'); // $ExpectType Promise<true>
|
||||
spec.notExists('View.MissingSample'); // $ExpectType Promise<true>
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
<Tester specs={[sampleSpec]} waitTime={42}>
|
||||
<HookedSampleComponent foo="test" />
|
||||
</Tester>;
|
||||
40
types/cavy/index.d.ts
vendored
Normal file
40
types/cavy/index.d.ts
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
// Type definitions for cavy 0.6
|
||||
// Project: https://github.com/pixielabs/cavy
|
||||
// Definitions by: Tyler Hoffman <https://github.com/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 extends {}> = T & { generateTestHook: TestHookGenerator };
|
||||
|
||||
export function hook<T extends {}>(component: React.ComponentClass<WithTestHook<T>>): React.ComponentClass<T>;
|
||||
|
||||
export interface TesterProps {
|
||||
specs: Array<(spec: TestScope) => void>;
|
||||
waitTime: number;
|
||||
sendReport?: boolean;
|
||||
}
|
||||
|
||||
export class Tester extends React.Component<TesterProps> {
|
||||
reRender(): void;
|
||||
clearAsync(): Promise<void>;
|
||||
}
|
||||
|
||||
export class TestScope {
|
||||
component: Tester;
|
||||
findComponent(identifier: string): Promise<React.Component>;
|
||||
describe(label: string, fn: () => void): void;
|
||||
it(label: string, fn: () => void): void;
|
||||
press(identifier: string): Promise<void>;
|
||||
fillIn(identifier: string, str: string): Promise<void>;
|
||||
pause(time: number): Promise<void>;
|
||||
exists(identifier: string): Promise<true>;
|
||||
notExists(identifier: string): Promise<true>;
|
||||
}
|
||||
24
types/cavy/tsconfig.json
Normal file
24
types/cavy/tsconfig.json
Normal file
@@ -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"
|
||||
]
|
||||
}
|
||||
1
types/cavy/tslint.json
Normal file
1
types/cavy/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user