Cannot run preview mode when test with Jest
I forget to add editor wrap element in current document so editor initializing by me was not existing in DOM The solution on 12 line: <img width="488" alt="solution" src="https://user-images.githubusercontent.com/48758473/90397413-77f2a000-e0a0-11ea-9f99-c8d43fef06c8.png">
Read full answer below ↓Question
Version: 0.15.10
Hi!
I am using Jest for testing my Grapes.js components. I need test my components behavior in a different environment like an edit mode and preview mode in Grapes.js editor. When I test in edit mode everything is fine but when I need test in preview mode I try to run script editor.runCommand('preview') and I get error. The tests are working in node.js but I succeeded to debug it in Google developer panel, so we can touch the code from within.

If we get to the point where the error appears, we understand that this.getDoc() returns null:

When I start my Grapes.js project in usual mode I saw in debugger that this.getDoc() must return contentDocument of iframe element:

So someone have any ideas how to solve the problem with contentDocument is null in Jest?
Answers (1)
I forget to add editor wrap element in current document so editor initializing by me was not existing in DOM
The solution on 12 line:
<img width="488" alt="solution" src="https://user-images.githubusercontent.com/48758473/90397413-77f2a000-e0a0-11ea-9f99-c8d43fef06c8.png">Related Questions and Answers
Continue research with similar issue discussions.
Issue #6409
Cannot drag to move components on mobile
GrapesJS version [x] I confirm to use the latest version of GrapesJS What browser are you using? Chrome v133 Reproducible demo link https:/...
Issue #3126
Video throwing error
on click to upload button side preview works fine but when clicking on that video preview it throws error and rest of all images stop worki...
Issue #2637
[Bug]: Preview mode & automatic components borders toggling
Hello again :) Our team recently started customising the editor & removing the webpage preset, and we might have found some bugs related to...
Issue #4474
Running in headless mode requires window
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? Chrome 103.0.5060.134Reproducible demo link...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.
Browse premium plugins →Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.