I am using the same token "abc" multiple times in my tests in a single file.
For example :
fetchMock.mockResponseOnce(JSON.stringify({ jwtToken, refreshToken: "abc" }));
My team suggests that I declare a const with a value and use it instead.
const refreshToken = "abc";
fetchMock.mockResponseOnce(JSON.stringify({ jwtToken, refreshToken }));
I do not see any benefits for the same. Suggestions ? My thoughts are that since tests are individual methods having the refresh token value in the test makes better sense to me in terms of readability and also does not increase my code line when I declare a global const.
Thank you.
Probably, this is not about increasing the code.
As you can see, If you declare the token as a variable in starting of your file or say a common place. Then, you can change the token (if necessary ever) from just a single place instead of going through line by line.
This is more of a pattern. And maybe in this case you don't need this. But, using constants from a single place is a widely accepted pattern.
Ideally, you should put all such variables in a common place. For example: A config or environment file.