我试图输入组件的属性并同时使用URL参数。我收到以下错误:
类型“ Readonly <{children?:ReactNode}>和Readonly”上不存在属性“ match”
这是我的一些代码:
import Api from '../../api/Api';
interface MyProps {
api: Api
}
interface MyState {
someString: string,
loading: boolean
}
export class MyComponent extends React.Component<MyProps, MyState> {
constructor(props: MyProps) {
super(props);
this.state = {
someString: this.props.match.params.someString,//<-- Error is here on this line
loading: true
}
}
componentDidMount() {
this.props.api.getSomeInfo(this.state.someString, this.callback)
}
callback() {
let interval = setInterval(function () {
this.setState({loading: false});
clearInterval(interval)
}, 3000);
}
render() {
return (
<div>
<p>{this.someString}</p>
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我正在尝试做的是: …
我有一个包装蚂蚁设计形式的组件,如下所示:
export interface IMyProps {
onSubmit: () => void,
anInput: React.ReactNode
}
export class MyForm extends React.Component<IMyProps> {
constructor(props: any) {
super(props)
}
render() {
return (
<Form onSubmit={this.props.onSubmit}>
{this.props.anInput}
</Form>
)
}
}
Run Code Online (Sandbox Code Playgroud)
我希望能够将任何ReactNode传递给我的表单结构和一个处理表单提交的函数。
因此,我还有一个用于定义传递给MyForm的组件的组件:
export interface IDecoratorProps extends FormComponentProps {
onSubmit: () => void,
value: string
}
class MyDecoratedForm extends React.Component<IDecoratorProps> {
constructor(props: any) {
super(props)
}
render() {
return (
<div>
<MyForm
onSubmit={this.props.onSubmit}
anInput={
<Form.Item
label={"label"}
hasFeedback>
{
this.props.form.getFieldDecorator(
"label",
{
rules: [{required: true, message: 'This is …Run Code Online (Sandbox Code Playgroud) 我正在使用JQuery UI Tooltip和AJAX来验证表单.
我正在为每个字段使用一个工具提示,我正在根据我的AJAX返回的错误更改此工具提示的内容.
为了使我的代码完整,我需要测试工具提示是否已经为此字段初始化(更改内容),否则(创建工具提示).
问题是我不知道检查工具提示是否初始化的任何情感方法.
HTML:
<input type="text" id="text1"/>
<input type="text" id="text2"/>
Run Code Online (Sandbox Code Playgroud)
我尝试了以下但是他们都无法测试工具提示是否已经创建.
JQUERY:
if($("#text1").tooltip() != null) //or $("#text1").tooltip() != 'undefined'
//does'nt work because .tooltip() always return an object.
if(typeof $("#text1").tooltip() != null)//or typeof $("#text1").tooltip() != 'undefined'
//does'nt work always return an object.
if($("#text1").tooltip().hasOwnProperty('option'))//or $("#text1").tooltip().hasOwnProperty('content')
//does'nt work it always return false.
Run Code Online (Sandbox Code Playgroud)
如果有人可以帮我找到一种方法来检查工具提示是否存在,那就非常感激了
谢谢!
我在这里尝试测试以下代码:
public class Something {
public String doSomething(MyClass myClass) {
return Utils.getPresentationString(myClass)
}
}
public class Utils{
public static String getPresentationString(MyClass myClass) {
if (myClass instanceof MySubClass) {
MySubClass mySubClass = (MySubClass) myClass;
return mySubClass.getMaskedPresentationString();
} else {
return myClass.getPresentationString();
}
}
}
Run Code Online (Sandbox Code Playgroud)
由于Utils是静态的,因此我在测试Something类时以黑盒方式对其进行了测试。
我试图让这行代码返回一个模拟:
MySubClass mySubClass = (MySubClass) myClass;
Run Code Online (Sandbox Code Playgroud)
所以我可以做
doReturn(MY_MASKED_STRING).when(this.mySubClassMock).getMaskedPresentationString()
Run Code Online (Sandbox Code Playgroud)
然后做
assertEquals(MY_MASKED_STRING, this.somethingUnderTest.doSomething(this.myClassMock))
Run Code Online (Sandbox Code Playgroud)
我该如何做这样的工作
doReturn(this.mySubClassMock).when(this.myClassMock).<<cast to MySubClass.class>>
Run Code Online (Sandbox Code Playgroud)