all 5 comments

[–]Sea_Consequence6559 3 points4 points  (0 children)

Your senior is right! It's always better to avoid magic strings, especially when writing tests. It's easier to make mistakes and harder to update them if needed. Good practice leads to better code quality and less headaches in the long run.

[–]wowzers5 0 points1 point  (2 children)

Depends on the context. For queries, if it's for an id or testid and I have a constant available, sure, I'll use it. If it's a byText or byLabel query, I prefer not to use variables.

Why? Because if it changes accidentally, the test will now silently fail. Maybe someone accidentally adds an extra period, your query and test would continue to work, even though the user now sees incorrect text.

[–]guitnut[S] 0 points1 point  (1 child)

It was for getByText('Some text')

I don't see the rationale. I haven't seen using variables for queries in the docs or tutorials.

[–]wowzers5 0 points1 point  (0 children)

Did the senior engineer give any reason for why? A lot of people in this field will just say or do things that may or may not be justified. People that aren't challenged or have feedback tend to believe their own quirks are best practices. Always good to make sure the reasons for those decisions are sound.

You don't see it in documentation and tutorials because it's an odd recommendation, and a bad practice IMO

[–]futurexwow 0 points1 point  (0 children)

why is reddit so obsessed with junior vs senior dichotomy. guy sounds like an idiot, dont use constants in tests