You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found a way to have expectations fail, but not bubble to fail the test. If I do something like this in my test, the failed expectation will be caught by the code further below.
try {
const validParams = {}; // real stuff in code
return axios(validParams);
}
catch (e) {
// If third party fails, doing a graceful return instead of throwing
myFunctionThatLogs();
return [];
}
Basically my code is catching the error that moxios is throwing and everything runs as normal. Not honestly sure there is a way around this, but wanted to call it out if there's some best practice I'm missing.
The text was updated successfully, but these errors were encountered:
I was seeing the same thing. This seems to be a weird scope issue in try-catch blocks. Some investigation should go into this but to mitigate this use the chaining technique for promise resolution. This is what I did in Typescript but should work for Javascript implementations as well.
publicpost=async<T,B>(url: string,headers: Record<string,string>,body?: B|undefined): Promise<T>=>{constdata=axios.post<T>(url,this.buildOptions(headers,body)).then((res)=>{if(res.status!==200){logger.error(`Received ${res.status} status when hitting ${url}`);throwError('Error interacting with integration layer');}returnres.dataasT;}).catch((err)=>{logger.error(`Error when hitting ${url} with ${err.code}`,err.message,err.stack);throwError(`${err.code} error interacting with integration layer: ${err.message}${err.stack}`);});returndata;};
I found a way to have expectations fail, but not bubble to fail the test. If I do something like this in my test, the failed expectation will be caught by the code further below.
From my test file:
From my actual file:
Basically my code is catching the error that moxios is throwing and everything runs as normal. Not honestly sure there is a way around this, but wanted to call it out if there's some best practice I'm missing.
The text was updated successfully, but these errors were encountered: