TestCafe t.eval vs. ClientFunction

Viewed 227

What is the difference between TestCafes t.eval() function and ClientFunctions?

I've been using TestCafe for a while now and didn't stumble across the eval function until now.

I am curious, but I also have a concrete use case, which is not the subject of this question, but might help me understand the difference between both. I'd like to do simple page manipulation tasks like hiding elements from my tests code. The documentation clearly says that ClientFunction should not be used for this: "Do not modify the tested webpage within client functions. Use test actions to interact with the page instead." Is the eval function suitable for this?

1 Answers

In essence, they are the same. The difference is that ClientFunction creates an instance that can be saved to a variable and then reused several times, while t.eval works without saving. Also, t.eval is executed immediately, while ClientFunction is not - it creates an instance that you need to call explicitly in order to run it.

Related