我用酶编写单元测试并尝试调用组件的方法。
let wrapper = mount(<Provider>
<MyComponent />
</Provider>);
如何调用MyComponent的方法?
答案 0 :(得分:1)
我会为此做一个浅包装。
#include <iostream>
using namespace std;
int main(){
char choice;
int num1, num2;
int getNums();
int operatorChoice()
int multiply(int, int);
int subtract(int, int);
int add(int, int);
void outputResult(int);
getNums();
int result;
operatorChoice();
if(choice == 'A'){
add(num1,num2);
}
if(choice == 'S'){
subtract(num1, num2);
}else{
multiply(num1,num2);
outputResult(result);
return 0;
}
}
int getNums(){
int num1,num2;
cout << "Enter an integer " << endl;
cin >> num1;
cout << "Enter an integer " << endl;
cin >> num2;
return num1, num2;
}
int operatorChoice(){
char choice;
cout << "Enter A to add, S to subtract, or M to multiply " << endl;
cin >> choice;
while(choice != 'A' && choice !='S' && choice != 'M'){
cout << "Invalid choice. Enter A to add, S to subtract, or M to
multiply ";
cin >> choice;
}
return choice;
}
int add(){
int num1, num2;
int result;
result = num1 + num2;
return result;
}
int subtract(){
int num1, num2;
int result;
result = num1 - num2;
return result;
}
int multiply(){
int num1, num2;
int result;
result = num1 * num2;
return result;
}
void outputResult(){
int result;
cout << "The result is " << result << endl;
}