fix(enzyme): change generic P,S params typo in shallow/mount (#27255)

This commit is contained in:
Martin Hochel
2018-07-15 12:23:01 -07:00
committed by Ryan Cavanaugh
parent dcd53299bf
commit e731338239
2 changed files with 57 additions and 2 deletions
+55
View File
@@ -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} />);
+2 -2
View File
@@ -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>;