mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
[@types/cavy] Update generateTestHook function types (#37204)
* Update generateTestHook function types * Empty commit for Travis
This commit is contained in:
parent
82f8b9305e
commit
e0a244294d
@ -8,11 +8,22 @@ type Props = WithTestHook<{
|
||||
}>;
|
||||
|
||||
class SampleComponent extends React.Component<Props> {
|
||||
textInputRef: React.ReactNode | null;
|
||||
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
this.textInputRef = null;
|
||||
}
|
||||
|
||||
setTextInputRef = (el?: React.ReactNode) => {
|
||||
this.textInputRef = el;
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<View ref={this.props.generateTestHook('View.Sample')}>
|
||||
<Text>{this.props.foo}</Text>
|
||||
<TextInput ref={this.props.generateTestHook("Input.Sample")} />
|
||||
<TextInput ref={this.props.generateTestHook("Input.Sample", this.setTextInputRef)} />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@ -22,9 +33,8 @@ const HookedSampleComponent = hook(SampleComponent); // $ExpectType ComponentCla
|
||||
|
||||
const SampleFunctionComponent: React.FunctionComponent = () => {
|
||||
const generateTestHook = useCavy();
|
||||
return (
|
||||
<View ref={generateTestHook(`FunctionView.Sample`)}></View>
|
||||
);
|
||||
const ref = React.createRef();
|
||||
return <View ref={generateTestHook(`FunctionView.Sample`, ref)}></View>;
|
||||
};
|
||||
|
||||
function sampleSpec(spec: TestScope) {
|
||||
|
||||
7
types/cavy/index.d.ts
vendored
7
types/cavy/index.d.ts
vendored
@ -1,4 +1,4 @@
|
||||
// Type definitions for cavy 2.0
|
||||
// Type definitions for cavy 2.2
|
||||
// Project: https://github.com/pixielabs/cavy
|
||||
// Definitions by: Tyler Hoffman <https://github.com/tyler-hoffman>
|
||||
// Abigail McPhillips <https://github.com/AbigailMcP>
|
||||
@ -11,7 +11,10 @@ export {};
|
||||
|
||||
type RefCallback = (element: React.ReactNode | null) => void;
|
||||
|
||||
export type TestHookGenerator = (label: string, callback?: RefCallback) => RefCallback;
|
||||
type TestHookGeneratorWithRefCallback = (label: string, ref?: RefCallback) => RefCallback;
|
||||
type TestHookGeneratorWithRefObject = (label: string, ref?: React.RefObject<any>) => React.RefObject<any>;
|
||||
|
||||
export type TestHookGenerator = TestHookGeneratorWithRefCallback & TestHookGeneratorWithRefObject;
|
||||
|
||||
export type WithTestHook<T extends {}> = T & { generateTestHook: TestHookGenerator };
|
||||
|
||||
|
||||
@ -21,4 +21,4 @@
|
||||
"index.d.ts",
|
||||
"cavy-tests.tsx"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user