Skip to content

Commit

Permalink
test(test-helpers): fix changes to setupPasteSupport causing test fai…
Browse files Browse the repository at this point in the history
…lures
  • Loading branch information
b-kelly committed Jul 21, 2022
1 parent 0bf0bdf commit aa50811
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
13 changes: 10 additions & 3 deletions test/rich-text/test-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function runCommand(
}

/** Sets up ProseMirror paste support globally for jsdom */
export function setupPasteSupport(dropElement?: Element): void {
export function setupPasteSupport(): void {
Range.prototype.getClientRects = () => ({
item: () => null,
length: 0,
Expand All @@ -115,14 +115,21 @@ export function setupPasteSupport(dropElement?: Element): void {

Range.prototype.getBoundingClientRect = () =>
jest.mocked<DOMRect>({} as never);

Document.prototype.elementFromPoint = () => dropElement;
}

/** Tears down ProseMirror paste support globally for jsdom */
export function cleanupPasteSupport(): void {
Range.prototype.getClientRects = undefined;
Range.prototype.getBoundingClientRect = undefined;
}

/** Sets up ProseMirror drop support globally for jsdom */
export function setupDropSupport(dropElement: HTMLElement) {
Document.prototype.elementFromPoint = () => dropElement;
}

/** Tears down ProseMirror drop support globally for jsdom */
export function cleanupDropSupport() {
Document.prototype.elementFromPoint = () => undefined;
}

Expand Down
8 changes: 5 additions & 3 deletions test/shared/prosemirror-plugins/image-upload.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EditorState, PluginView } from "prosemirror-state";
import { EditorState } from "prosemirror-state";
import { EditorView } from "prosemirror-view";
import { RichTextEditor } from "../../../src/rich-text/editor";
import {
Expand All @@ -18,9 +18,11 @@ import {
import { commonmarkSchema } from "../../../src/commonmark/schema";
import { stackOverflowValidateLink } from "../../../src/shared/utils";
import {
cleanupDropSupport,
cleanupPasteSupport,
dispatchDropEvent,
dispatchPasteEvent,
setupDropSupport,
setupPasteSupport,
testRichTextSchema,
} from "../../rich-text/test-helpers";
Expand Down Expand Up @@ -149,7 +151,7 @@ describe("image upload plugin", () => {
});

it("should handleDrop on editor", () => {
setupPasteSupport(view.editorView.dom);
setupDropSupport(view.editorView.dom);

let state = getPluginStateByName<{ file: File }>(
view.editorView.state,
Expand All @@ -170,7 +172,7 @@ describe("image upload plugin", () => {

expect(state.file).toBeTruthy();

cleanupPasteSupport();
cleanupDropSupport();
});

it("should handlePaste on editor", () => {
Expand Down

0 comments on commit aa50811

Please sign in to comment.