Я использую TestCafe для автоматизации пользовательского интерфейса, использую ClientFunctions для запуска запросов API (чтобы я мог передавать файлы cookie сеанса).
В настоящее время у меня есть ClientFunction с fetch , которая работает хорошо ... за исключением того, что мы сейчас тестируем IE 11 и Fetch не поддерживается.
Код извлечения:
const fetchRequestClientFunction = ClientFunction((details, endpoint, auth, method) => {
return window
.fetch(endpoint, {
method,
credentials: 'include',
headers: new Headers({
accept: 'application/json',
'Content-Type': 'application/json',
}),
body: JSON.stringify(details),
})
.then(httpResponse => {
if (httpResponse.ok) {
return httpResponse.json();
}
return {
err: true,
errorMessage: `There was an error trying to send the data ${JSON.stringify(
details
)} to the API endpoint ${endpoint}. Status: ${httpResponse.status}; Status text: ${httpResponse.statusText}`,
};
});
});
Однако, когда я пытаюсь переключить его на ax ios ... не так уж много:
import axios from 'axios';
const axiosRequest = ClientFunction((details, endpoint, auth, method) => {
return axios({
method,
auth,
url: endpoint,
data: details,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
timeout: 3000,
})
.then(httpResponse => {
if (httpResponse.status < 300) return httpResponse;
return {
err: true,
errorMessage: `There was an error trying to send the data ${JSON.stringify(
details
)} to the API endpoint ${endpoint}. Status: ${httpResponse.status}; Status text: ${httpResponse.statusText}`,
};
});
});
Пробовал использовать window.axios
, а также передавать axios
в качестве зависимости. Я также пытался сделать запрос ax ios без ClientFunction ... и, несмотря на получение ответа 200, веб-сайт не обновлялся, как ожидалось.
Каждый раз, когда я получаю _axios2 is not defined
или window.axios is not a function
. Я был бы очень признателен за некоторые указания здесь.