This was a really fun question from @rightsaidjames in the Slack Ask Me Anything with @marie.drake and Filip Hric
Whatโs your favourite Cypress command?
Filip responded with
wow, Iโm so enjoying this such a cool question
I really love when I teach using Cypress and people literally freak out when they use network request stubbing, so it has to be combination of.server()
.route()
.as()
and
.wait()
although Iโm also really enjoying using.contains()
command. it selects an element using text, which is neat and makes test super readable. also, you can specify this command by using.contains('button', 'Send')
which is just going to selectbutton
elements that containSend
text.one more thing comes to mind - some of my favourites are my own custom commands! recently I had a lot of fun rewriting my tests to typescript and creating custom types for them. this meant that I could customize my autocomplete in VS code and make commands that reflected my app logic
And Marie added
I like the
invoke()
command because of its versatility. You can invoke any attributes and either query it or update its value. I also like thecy.request()
because with this command, I can test APIs too cypress aliases too.as()
because you can use this with fixtures, data selectors, requests, anything! itโs very handy
What about you? Whatโs your favourite Cypress command?