Recently, I have implemented a practice in my tests where I encapsulate error messages and string manipulations into methods or variables to enhance the resilience of my tests in case the content of error messages changes in the future.
For instance, I would modify code like this:
try{
someMethod();
}catch(e){
throw new Error('error message.');
}
to something like this:
let errorMessage = 'error message';
...
try{
someMethod();
}catch(e){
throw new Error(errorMessage);
}
I apply similar modifications if the error message involves a variable or other dynamic elements.
My inquiry pertains to the best approach to achieve this in Typescript. In Java, I usually designate them as package-protected, but it appears that Jasmine does not have access to such methods when they are protected. I also experimented with making them static.
Is there a recommended strategy for handling this scenario?