[@types/cavy] Update cavy types for beforeEach and useCavy functions (#35256)

* Add beforeEach and useCavy function types to Cavy

* Linting and version update
This commit is contained in:
AbigailMcP
2019-05-13 15:39:16 -07:00
committed by Nathan Shively-Sanders
parent 6b2d933449
commit ddf184c96f
2 changed files with 16 additions and 2 deletions
+11 -1
View File
@@ -1,7 +1,7 @@
import * as React from 'react';
import { TextInput, View, Text } from 'react-native';
import { hook, TestScope, WithTestHook, Tester } from 'cavy';
import { hook, TestScope, WithTestHook, Tester, useCavy } from 'cavy';
type Props = WithTestHook<{
foo: string;
@@ -20,8 +20,17 @@ class SampleComponent extends React.Component<Props> {
const HookedSampleComponent = hook(SampleComponent); // $ExpectType ComponentClass<{ foo: string; }, any>
const SampleFunctionComponent: React.FunctionComponent = () => {
const generateTestHook = useCavy();
return (
<View ref={generateTestHook(`FunctionView.Sample`)}></View>
);
};
function sampleSpec(spec: TestScope) {
spec.describe('it has a name and callback', () => {
spec.beforeEach(() => {});
spec.it('it has a name and callback', async () => {
spec.component.reRender(); // $ExpectType void
spec.component.clearAsync(); // $ExpectType Promise<void>
@@ -37,4 +46,5 @@ function sampleSpec(spec: TestScope) {
<Tester specs={[sampleSpec]} waitTime={42}>
<HookedSampleComponent foo="test" />
<SampleFunctionComponent/>
</Tester>;
+5 -1
View File
@@ -1,6 +1,7 @@
// Type definitions for cavy 0.6
// Type definitions for cavy 2.0
// Project: https://github.com/pixielabs/cavy
// Definitions by: Tyler Hoffman <https://github.com/tyler-hoffman>
// Abigail McPhillips <https://github.com/AbigailMcP>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
@@ -16,6 +17,8 @@ export type WithTestHook<T extends {}> = T & { generateTestHook: TestHookGenerat
export function hook<T extends {}>(component: React.ComponentClass<WithTestHook<T>>): React.ComponentClass<T>;
export function useCavy(): TestHookGenerator;
export interface TesterProps {
specs: Array<(spec: TestScope) => void>;
waitTime: number;
@@ -32,6 +35,7 @@ export class TestScope {
findComponent(identifier: string): Promise<React.Component>;
describe(label: string, fn: () => void): void;
it(label: string, fn: () => void): void;
beforeEach(fn: () => void): void;
press(identifier: string): Promise<void>;
fillIn(identifier: string, str: string): Promise<void>;
pause(time: number): Promise<void>;