BUG: Cannot run preview mode when test with Jest
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
BUG: 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 #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 #2422
[BUG] Unable to add 'space' character if zoom is applied on canvas
Cannot edit text components properly if a zoom value is applied on the canvas. GrapesJS version:0.15.8 The issue can be reproduced in the d...
Issue #2904
BUG: dragging components in preview mode enables editor mode
We can reproduce the bug from the demo Current Behavior: Expected Behavior: We should not be able to drag/move components when in preview m...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.