mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 15:00:26 +00:00
fix(enzyme): change generic P,S params typo in shallow/mount (#27255)
This commit is contained in:
committed by
Ryan Cavanaugh
parent
dcd53299bf
commit
e731338239
@@ -86,6 +86,34 @@ function ShallowWrapperTest() {
|
||||
let anotherStatelessWrapper: ShallowWrapper<AnotherStatelessProps, never>;
|
||||
let anotherComponentWrapper: ShallowWrapper<AnotherComponentProps, any>;
|
||||
|
||||
// testStatePropsInstanceFn(shallow<MyComponent>(<MyComponent stringProp="value" numberProp={1}/>));
|
||||
function testStatePropsInstance() {
|
||||
const wrapper = shallow<MyComponent>(<MyComponent stringProp="value" numberProp={1}/>);
|
||||
|
||||
const {
|
||||
numberProp, // $ExpectType number
|
||||
stringProp // $ExpectType string
|
||||
} = wrapper.props();
|
||||
const {
|
||||
stateProperty // $ExpectType string
|
||||
} = wrapper.state();
|
||||
const {
|
||||
handleEcho // $ExpectType (value: string) => string
|
||||
} = wrapper.instance();
|
||||
|
||||
// $ExpectError
|
||||
wrapper.setState({stateProperty: 123});
|
||||
// $ExpectError
|
||||
wrapper.setState({statePropertyzasd: 'hello'});
|
||||
wrapper.setState({stateProperty: 'hello'});
|
||||
|
||||
// $ExpectError
|
||||
wrapper.setProps({numberProp: '123'});
|
||||
// $ExpectError
|
||||
wrapper.setProps({numberPropzasd: 'hello'});
|
||||
wrapper.setProps({numberProp: 123});
|
||||
}
|
||||
|
||||
function test_props_state_inferring() {
|
||||
let wrapper: ShallowWrapper<MyComponentProps, MyComponentState>;
|
||||
wrapper = shallow(<MyComponent stringProp="value" numberProp={1} />);
|
||||
@@ -455,6 +483,33 @@ function ReactWrapperTest() {
|
||||
let anotherStatelessWrapper: ReactWrapper<AnotherStatelessProps, never>;
|
||||
let anotherComponentWrapper: ReactWrapper<AnotherComponentProps, any>;
|
||||
|
||||
function testStatePropsInstance() {
|
||||
const wrapper = mount<MyComponent>(<MyComponent stringProp="value" numberProp={1}/>);
|
||||
|
||||
const {
|
||||
numberProp, // $ExpectType number
|
||||
stringProp // $ExpectType string
|
||||
} = wrapper.props();
|
||||
const {
|
||||
stateProperty // $ExpectType string
|
||||
} = wrapper.state();
|
||||
const {
|
||||
handleEcho // $ExpectType (value: string) => string
|
||||
} = wrapper.instance();
|
||||
|
||||
// $ExpectError
|
||||
wrapper.setState({stateProperty: 123});
|
||||
// $ExpectError
|
||||
wrapper.setState({statePropertyzasd: 'hello'});
|
||||
wrapper.setState({stateProperty: 'hello'});
|
||||
|
||||
// $ExpectError
|
||||
wrapper.setProps({numberProp: '123'});
|
||||
// $ExpectError
|
||||
wrapper.setProps({numberPropzasd: 'hello'});
|
||||
wrapper.setProps({numberProp: 123});
|
||||
}
|
||||
|
||||
function test_prop_state_inferring() {
|
||||
let wrapper: ReactWrapper<MyComponentProps, MyComponentState>;
|
||||
wrapper = mount(<MyComponent stringProp="value" numberProp={1} />);
|
||||
|
||||
Vendored
+2
-2
@@ -589,14 +589,14 @@ export interface MountRendererProps {
|
||||
* Shallow rendering is useful to constrain yourself to testing a component as a unit, and to ensure that
|
||||
* your tests aren't indirectly asserting on behavior of child components.
|
||||
*/
|
||||
export function shallow<C extends Component, P = Component['props'], S = Component['state']>(node: ReactElement<P>, options?: ShallowRendererProps): ShallowWrapper<P, S, C>;
|
||||
export function shallow<C extends Component, P = C['props'], S = C['state']>(node: ReactElement<P>, options?: ShallowRendererProps): ShallowWrapper<P, S, C>;
|
||||
export function shallow<P>(node: ReactElement<P>, options?: ShallowRendererProps): ShallowWrapper<P, any>;
|
||||
export function shallow<P, S>(node: ReactElement<P>, options?: ShallowRendererProps): ShallowWrapper<P, S>;
|
||||
|
||||
/**
|
||||
* Mounts and renders a react component into the document and provides a testing wrapper around it.
|
||||
*/
|
||||
export function mount<C extends Component, P = Component['props'], S = Component['state']>(node: ReactElement<P>, options?: MountRendererProps): ReactWrapper<P, S, C>;
|
||||
export function mount<C extends Component, P = C['props'], S = C['state']>(node: ReactElement<P>, options?: MountRendererProps): ReactWrapper<P, S, C>;
|
||||
export function mount<P>(node: ReactElement<P>, options?: MountRendererProps): ReactWrapper<P, any>;
|
||||
export function mount<P, S>(node: ReactElement<P>, options?: MountRendererProps): ReactWrapper<P, S>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user