Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any guides for testing with this thing? #557

Open
dwjohnston opened this issue Aug 29, 2023 · 2 comments
Open

Any guides for testing with this thing? #557

dwjohnston opened this issue Aug 29, 2023 · 2 comments
Labels

Comments

@dwjohnston
Copy link

dwjohnston commented Aug 29, 2023

I'm wanting to write some tests against our our customised version of this tool. I'm having trouble with both Testing Library and Cypress.

With testing library - I can do this:

    userEvent.type(screen.getByRole("textbox"), "some plain text");

But I can't test keyboard short cuts like:

    userEvent.type(screen.getByRole("textbox"), "hello{meta}b{meta/}world")

With cypress I'm finding that I can enter text like:

 cy.get('.CodeMirror').type(
      "aaa"
    );

Also:

    cy.get('.CodeMirror').type(
      "hello{meta+b}world"
    );

Any other guides/best practises for testing?

@Ionaru
Copy link
Owner

Ionaru commented Sep 15, 2023

The tests in this repo may be a good example: https://github.com/Ionaru/easy-markdown-editor/tree/master/cypress/e2e

As far as testing keyboard shortcuts I have not tried that.

@dwjohnston
Copy link
Author

@Ionaru

I've written a guide for testing here: https://blacksheepcode.com/posts/testing_easy_mde

The main take away is:

  • There's all sorts of difficulties testing when it's in inputStyle: "textarea" mode. It comes down to that there are two textareas - and the textarea that you can interact with won't always contain the full value of the text editor (eg. initial values), which can make for trouble when making assertions on content or form submissions.
  • Contenteditable is much more reliable - but this wont' work in JSDOM based testing solutions like React Testing Library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants