-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathrunSafelyInEditor.test.ts
More file actions
37 lines (27 loc) · 1.08 KB
/
Copy pathrunSafelyInEditor.test.ts
File metadata and controls
37 lines (27 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import type { Editor } from '@tiptap/react';
import { runSafelyInEditor } from '../utils/runSafelyInEditor';
function makeEditor(isDestroyed: boolean): Editor {
return { isDestroyed } as Editor;
}
describe('runSafelyInEditor', () => {
test('runs the callback and returns its result when editor is alive', () => {
const editor = makeEditor(false);
const callback = jest.fn((e: Editor) => e);
const result = runSafelyInEditor(editor, callback);
expect(callback).toHaveBeenCalledWith(editor);
expect(result).toBe(editor);
});
test('does not run the callback and returns null when editor is destroyed', () => {
const editor = makeEditor(true);
const callback = jest.fn();
const result = runSafelyInEditor(editor, callback);
expect(callback).not.toHaveBeenCalled();
expect(result).toBeNull();
});
test('does not run the callback and returns null when editor is null', () => {
const callback = jest.fn();
const result = runSafelyInEditor(null, callback);
expect(callback).not.toHaveBeenCalled();
expect(result).toBeNull();
});
});