Cypress: Error: Syntax error, unrecognized expression – How to escape
Fabian Blechschmidt
I’m writing Cypress tests for our first hopefully-soon-to-be-purchased Shopware plugin and stumbled over:
Error: Syntax error, unrecognized expression: a[href=#/sw/product/create]
The problem? Cypress is using jQuery internally and therefore you need to escape the parameter for cy.get
properly.
Thankfully K K Agrawal wrote a blogpost about how to do that! He added a method to do it but unfortunately no easy to read list of all the characters which needs to be escaped, so here is our list.
Escaping works with one backslash, like \.
!
# So my
cy.get('a[href^="#/sw/product/create"]').click();
# needed to be
cy.get('a\[href\^\=\"\#\/sw\/product\/create\"\]').click();
P.S. I don’t know why, but my tests with Cypress.$.escapeSelector()
didn’t work ?
Other articles from this category
PHPStorm/IDEA, composer updates and 100% CPU
In one of our projects PHPStorm ran a while on 100% CPU, an investigation showed, that the process „checking for available composer updates“ ran and used all the resources. Most likely it got stuck somewhere. To get rid of the problem, one can turn off this feature. In IDEA Ultimate here: [Settings] -> Languages & […]
Custom Fields, dots and MySQL’s JSON_EXTRACT
We all know custom fields – hopefully – at least this is not about the basics. You can add custom fields to nearly all entites: orders, products, categories, … You can name them whatever you like, e.g. pluginname.property – but using dots . in your custom field name is a bad idea, because then you […]
gpg failed to sign the data
I was doing some work, when suddenly my git failed to commit changed. I dig a little around, asked StackOverflow but it didn’t help. Finally when running the commit manually and not through PHPStorm I got a proper error: Ah! The key is expired! Got it. Did you know you can extend a GPG key? […]