После некоторых изменений в существующем компоненте у меня возникают проблемы в шутливых тестах.
По сути, я добавил вызов функции componentDidMount к функции, которая выполняет внутреннюю «выборку», и теперь я получаю сообщение об ошибке при запуске шутных тестов
![enter image description here](https://i.stack.imgur.com/dveBx.png)
fetch вызывается в utils / index.ts, а этот вызывается из MyComponent.tsx
componentDidMount() {
this.props.actions.requestLoadA();
this.props.actions.requestLoadB();
// Problematic call HERE
this.getXPTOStatuses("something");
}
getXPTOStatuses = (something: string) => {
HttpUtility.get(`/api/getXPTOStatuses?param=${something}`)
.then(response => handleFetchErrors(response))
.then(data => {
// ....
})
.catch(error => {
// show the error message to the user -> `Could not load participant statuses. Error: '${error.message}'`
});
}
и получить (...)
public static get = (url: string) => fetch(url, { method: "GET", headers: { Accept: "application/json" }, credentials: "same-origin" });
и шутка в деле:
MyContainer.test.tsx
describe("Risk Import Container Tests", () => {
let props: MyContainerProps;
beforeEach(() => {
props = initialProps;
});
it("Matches the snapshot", () => {
const props = initialProps;
const tree = shallow(<MyContainer {...props} />);
expect(tree).toMatchSnapshot();
});
});