DEV Community

Cover image for Answer: How can I clear a Codemirror editor field from Cypress
Jacob Evans
Jacob Evans

Posted on • Edited on

1 2

Answer: How can I clear a Codemirror editor field from Cypress

I was able to with a little help from another answer in the responses to come up with a solution.

  1. Problem domain involved embedded editor CodeMirror
  2. I wanted to use Cypress to remove all Text in a field then simulate a user typing in all their own, like a copy-paste.
  3. Could not remove code from the editor with Cypress as expected.

Normally I am afraid to use StackOverflow because I don't want to be shutdown or talked down too. I tweeted my question and got a great response; friendly and helpful! This is the type of interaction I love to see in StackOverflow.
Big thanks again to @evanplaice for seeing my tweet and helping out, here is his Twitter: https://twitter.com/evanplaice

The solution I ended up using looked something similar to code block in the question with a few changes.

  • I am not getting the window object from Cypress; CodeMirror editor wasn't there.

  • I used the idea Evan Plaice gave me related to the Editor instance being on the DOM and…

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay