From ddf184c96f29ff04a8496b5cf514e10d6f49dab1 Mon Sep 17 00:00:00 2001 From: AbigailMcP Date: Mon, 13 May 2019 23:39:16 +0100 Subject: [PATCH] [@types/cavy] Update cavy types for `beforeEach` and `useCavy` functions (#35256) * Add beforeEach and useCavy function types to Cavy * Linting and version update --- types/cavy/cavy-tests.tsx | 12 +++++++++++- types/cavy/index.d.ts | 6 +++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/types/cavy/cavy-tests.tsx b/types/cavy/cavy-tests.tsx index e33d0366a7..05f9032414 100644 --- a/types/cavy/cavy-tests.tsx +++ b/types/cavy/cavy-tests.tsx @@ -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 { const HookedSampleComponent = hook(SampleComponent); // $ExpectType ComponentClass<{ foo: string; }, any> +const SampleFunctionComponent: React.FunctionComponent = () => { + const generateTestHook = useCavy(); + return ( + + ); +}; + 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 @@ -37,4 +46,5 @@ function sampleSpec(spec: TestScope) { + ; diff --git a/types/cavy/index.d.ts b/types/cavy/index.d.ts index 5e74edfe48..985a7e3f46 100644 --- a/types/cavy/index.d.ts +++ b/types/cavy/index.d.ts @@ -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 +// Abigail McPhillips // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 3.0 @@ -16,6 +17,8 @@ export type WithTestHook = T & { generateTestHook: TestHookGenerat export function hook(component: React.ComponentClass>): React.ComponentClass; +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; describe(label: string, fn: () => void): void; it(label: string, fn: () => void): void; + beforeEach(fn: () => void): void; press(identifier: string): Promise; fillIn(identifier: string, str: string): Promise; pause(time: number): Promise;