lundi 8 juin 2020

When we declare a const and reuse the variable

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.

Aucun commentaire:

Enregistrer un commentaire