I feel that my question is very similar to the above but I'm also using a variable in my test assertion and I don't know how to get that into a regex for .match()
. I would prefer to stay away from regex, if possible, simply because I'm not too confident with it and it's one more thing to explain to a junior. I think that .toLowerCase
is a bit easier when instructing. However, if there is no good way to solve my following question without regex I will appreciate honest feedback.
My question
I have some text on page.
In the HTML it is <span>rock</span>
.
But there is CSS text-transform: uppercase;
so when I do .innerText
on the Selector I get "ROCK".
Perhaps in future the CSS will change and I don't think I should write tests that are able to be broken by CSS text-transform if I'm not testing that. So I'm looking for the most concise way to write a case insensitive assertion.
I thought, "ok, i can deal with this just using something like .toLowerCase()
to solve this by standardising the assertion inputs". But I can't find a 1 liner place where .toLowerCase
works.
I have managed to do this assertion in 2 lines of code. I was wondering if there's a 1 line way of doing the following (not including the first line which just illustrates the variable that already exists):
const myExpecting = 'rock' // used in multiple places
const textOnPage = await mySelector.innerText // resolves to 'ROCK'
await t.expect(textOnPage.toLowerCase()).contains(myExpecting) // assertion passes ✅
Any of the ways I have tried to combine the last 2 lines I end up with the error: .toLowerCase is not a function
. I'm new to testcafé and perhaps I just haven't seen a good example that shows this in the docs yet.
Thanks for reading,