We have an Angular project using the Monaco editor in the npm package ngx-monaco-editor-v2
version 17.0.1. We are running end-to-end tests using Cypress.
Using Cypress, I need a way to enter a block of text into the editor.
We currently have a method which I am not happy with:
cy.get("span[class='mtk1 bracket-highlighting-0']")
.eq(1)
.should('exist')
.type(`{selectall}{ctrl}{shift}K`, { delay: 100 })
cy.get('.view-line')
.should('have.text', '')
.type(cleanedJsonString, { delay: 0, release: false });
where cleanedJsonString
is the text to be entered into the editor.
This method is very slow, but it also screws up the formatting of the text.
Effectively, it enters line breaks, but never does a carriage return.
The text contains n as a line break. I have tried replacing it with rn,
but this didn’t change the result.
Rather than typing the text, it might be more effective to paste the text into the editor. I don’t know if this is possible, because writing to the clipboard from the browser is a security issue.
Does anyone know a good way to enter text into the Monaco editor using Cypress, in particular using the package ngx-monaco-editor-v2
in an angular project?