Search code examples
javascriptbootstrap-4rspeccapybaratogglebutton

How to click on pseudo-element when testing?


I have a switch / toggle element coming from bootstrap. It works perfectly as expected but I'm having trouble when testing the feature because I don't know how I can click on it:

the toggle is handled by the pseudo-elements :before & :after. I tried many pieces of code to simulate the click on it with capybara but I didn't find a way to achieve it...

Here the snippet: https://jsfiddle.net/ynuf96qe/

enter image description here

enter image description here

Anyone has an idea? Thank you!

Sorry for this element, I didn't find a way to bypass the link error from stackoverflow... <div></div>


Solution

  • I finally found a way out even if I don't like it...

    I changed the way the toggle is displayed in test environment: it is a simple checkbox that allows me to click on it through Capybara.

    It now works fine but I'm aware that is a hack.