我想为Axios使用Jest Framework编写测试。我正在使用Redux。
以下是 Axios 的功能获取请求
#home {
padding-top: 35px;
background-image: url("../images/homebg.jpg");
background-size: cover;
height: 100vh;
width: 100%;
}
@media (min-width: 480px) {
#home {
background: #fcb595;
}
}
提前感谢:)
答案 0 :(得分:0)
这是解决方案:
Mono
:
@Test
public void orTest() {
Mono<String> chain = Mono.<String>empty().switchIfEmpty(Mono.just("hello"));
StepVerifier.create(chain)
.expectNext("hello")
.verifyComplete();
}
index.ts
:
import axios from 'axios';
export const FETCH_DATA = 'FETCH_DATA';
export const ERROR_DATA = 'ERROR_DATA';
export const getRequest = a => dispatch => {
return axios
.get(a)
.then(response => {
dispatch({
type: FETCH_DATA,
payload: response.data
});
})
.catch(error => {
dispatch({ type: ERROR_DATA, payload: { status: error.response.status, statusText: error.response.statusText } });
});
};
单元测试结果和覆盖范围:
index.spec.ts
以下是代码:https://github.com/mrdulin/jest-codelab/tree/master/src/stackoverflow/45062447