我有一个React组件,它包含在高阶组件withRouter中,如下所示:
module.exports = withRouter(ManageProfilePage);
Run Code Online (Sandbox Code Playgroud)
我的路线如下:
<Route path="/" component={AdrApp}>
<IndexRoute component={Login}/>
<Route component={CheckLoginStatus}>
<Route path="manage-profiles/:profileId" component=
{ManageProfilesPage}/>
</Route>
<Route path="*" component={notFoundPage}/>
</Route>
Run Code Online (Sandbox Code Playgroud)
我需要使用一次Router生命周期方法,这就是我需要withRouter的原因:
class ManageProfilePage extends React.Component {
componentDidMount() {
this.props.router.setRouteLeaveHook(this.props.route, () => {
...
})
render(){
...
}
}
Run Code Online (Sandbox Code Playgroud)
我需要使用Jest/Enzyme测试这个组件,我编写了如下测试用例:
describe('manage profile page test suite', () => {
it('snapshot test', () => {
const setRouteLeaveHook =jest.fn();
let wrapper = shallow(
<ManageProfilePage params={{id : 25, router:
setRouteLeaveHook}}/>
);
expect(wrapper).toMatchSnapshot();
})
})
Run Code Online (Sandbox Code Playgroud)
问题是它没有渲染一个层次.我正在粘贴下面的快照:
exports[`manage drug term page test suites snapshot test 1`] …Run Code Online (Sandbox Code Playgroud) 给定一个数组,其所有元素都是正数,找到一个子序列的最大总和,其约束条件是序列中没有2个数字应该在数组中相邻.所以3 2 7 10应该返回13(3和10的总和)或3 2 5 10 7应该返回15(3,5和7的总和).
我尝试使用所有可能允许的总和,然后找到最大值(蛮力方法)但是有更好的方法.例如[3 2 7 10]我总和3,7和2,10并取最大值.
更多例子:
我正在从带有响应正文的后端代码发送状态代码422,其中包含错误的描述。我使用axios发布如下,以发布请求:
post: function(url, reqBody) {
const request = axios({
baseURL: config.apiUrl,
url: url,
headers: {
'Content-Type': 'application/json',
'Authorization': sessionStorage.getItem('token')
},
method: 'POST',
data: reqBody,
responseType: 'json'
});
return request
.then((res) => {
return res;
})
.catch((error) => {
console.log(error);
return error;
})
}
Run Code Online (Sandbox Code Playgroud)
问题是当后端返回错误代码422时,我正在捕获的错误对象没有有关响应主体的信息。有什么方法可以检索错误文本?
为什么在scanf函数中需要&符号(&).以下C代码中的输出或错误类型(编译或运行时)是什么?
#include <stdio.h>
void main() {
int a;
printf("enter integer:");
scanf("%d", a);
}
Run Code Online (Sandbox Code Playgroud) 我的方法界面是
Boolean isAuthenticated(String User)
Run Code Online (Sandbox Code Playgroud)
我想从值列表中比较,如果任何用户从列表中传递给函数,那么它应该返回true.
when(authService.isAuthenticated(or(eq("amol84"),eq("arpan"),eq("juhi")))).thenReturn(true);
Run Code Online (Sandbox Code Playgroud)
我正在使用额外的参数匹配'或'但上面的代码不起作用.我该如何解决这个问题?
我正在写一个笑话酶测试,如下所示:
import React from 'react';
import ManageDrugTermPage from '../js/manageDrugTermPage.jsx';
import toJson from 'enzyme-to-json';
describe('manage drug term page test suite', () => {
it('snapshot test', () => {
const setRouteLeaveHook =jest.fn();
let wrapper = shallow(
<ManageDrugTermPage params={{id : 25, router: setRouteLeaveHook}}/>
);
expect(toJson(wrapper)).toMatchSnapshot();
})
})
Run Code Online (Sandbox Code Playgroud)
我想在快照中查看ManageDrugTermPage的详细信息,但快照仅显示:
exports[`manage drug term page test suites snapshot test 1`] = `
<ManageDrugTermPage
params={
Object {
"id": 25,
"router": [Function],
}
}
/>
`;
Run Code Online (Sandbox Code Playgroud)
如何在快照中呈现ManageDrugTermPage?我不想使用renderer.create,但想通过酶做到这一点。
class One {
void foo() { }
}
class Two extends One {
private void foo() { /* more code here */ }
}
Run Code Online (Sandbox Code Playgroud)
为什么上面的代码片段错了?
这段代码编译得很好,但在运行时会出现分段错误错误?有谁能说出原因?
#include <stdio.h>
#include <string.h>
#include <math.h>
int main() {
const char s2[] = "asdfasdf";
char* s1;
strcpy(s1, s2);
printf("%s", s1);
return 0;
}
Run Code Online (Sandbox Code Playgroud) #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char *a = "Hello ";
const char *b = "World";
printf("%s", strcat(a, b));
system("PAUSE");
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud) 我正在用酶运行开玩笑,但我特别从我试图测试的类中的react-router依赖获得上述警告.我的问题是为什么我收到这个警告,因为我已经将我的反应版本降级为15.1.1.
Package.json
"dependencies": {
"axios": "^0.16.1",
"babel": "^6.23.0",
"babel-polyfill": "^6.23.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.5.0",
"bootstrap": "^3.3.5",
"boron": "^0.2.3",
"browserify": "^13.0.1",
"connect-history-api-fallback": "^1.2.0",
"debounce": "^1.0.0",
"envify": "^3.4.0",
"es6-promise": "^3.2.1",
"font-awesome": "^4.6.3",
"jquery": "^2.2.4",
"jwt-decode": "^2.2.0",
"minimist": "^1.2.0",
"node-fetch": "1.6.3",
"node-notifier": "^4.6.0",
"object-assign": "^4.1.0",
"react": "^15.1.0",
"react-autosuggest": "^3.8.0",
"react-dnd": "^2.1.4",
"react-dnd-html5-backend": "^2.1.2",
"react-document-title": "^2.0.3",
"react-dom": "^15.1.0",
"react-dropdown": "^1.0.4",
"react-quill": "^0.4.1",
"react-router": "^2.4.1",
"react-select": "^1.0.0-beta13",
"react-select2-wrapper": "^0.6.1",
"react-tag-input": "^3.0.3",
"reflux": "0.4.1",
"request": "^2.81.0",
"request-promise": "^4.2.0",
"toastr": "^2.1.0",
"underscore": "^1.8.3",
"vinyl-source-stream": "^1.1.0",
"watchify": "^3.7.0", …Run Code Online (Sandbox Code Playgroud) c ×4
enzyme ×3
jestjs ×3
reactjs ×3
react-router ×2
unit-testing ×2
algorithm ×1
axios ×1
cstring ×1
java ×1
javascript ×1
junit ×1
matcher ×1
methods ×1
mockito ×1
npm ×1
overriding ×1
post ×1
scanf ×1