forked from TypeCellOS/BlockNote
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlockNoteExtension.test.ts
More file actions
103 lines (91 loc) · 3.06 KB
/
Copy pathBlockNoteExtension.test.ts
File metadata and controls
103 lines (91 loc) · 3.06 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { expect, it } from "vitest";
import { createExtension, ExtensionOptions } from "./BlockNoteExtension.js";
import { BlockNoteEditor } from "./BlockNoteEditor.js";
const editor = BlockNoteEditor.create();
/**
* @vitest-environment jsdom
*/
it("creates an extension factory", () => {
const extension = createExtension(() => {
return {
key: "test",
prosemirrorPlugins: [],
} as const;
});
const extInstance = extension()({ editor });
expect(extInstance.key).toBe("test");
expect(extInstance.prosemirrorPlugins).toEqual([]);
});
it("creates an extension factory with options", () => {
const extension = createExtension((opts: ExtensionOptions<{ x: number }>) => {
expect(opts.options.x).toBe(1);
return {
key: "test",
prosemirrorPlugins: [],
} as const;
});
const extInstance = extension({ x: 1 })({ editor });
expect(extInstance.key).toBe("test");
expect(extInstance.prosemirrorPlugins).toEqual([]);
});
it("creates an extension factory with undefined options", () => {
const extension = createExtension(
(opts: ExtensionOptions<{ x: number } | undefined>) => {
expect(opts.options).toBe(undefined);
return {
key: "test",
prosemirrorPlugins: [],
} as const;
},
);
const extInstance = extension()({ editor });
expect(extInstance.key).toBe("test");
expect(extInstance.prosemirrorPlugins).toEqual([]);
});
it("creates an extension factory from an object", () => {
const extension = createExtension({
key: "test",
prosemirrorPlugins: [],
} as const);
const extInstance = extension({ editor });
expect(extInstance.key).toBe("test");
expect(extInstance.prosemirrorPlugins).toEqual([]);
});
it("allows arbitrary properties on a no-options extension", () => {
const extension = createExtension(() => {
return {
key: "test",
prosemirrorPlugins: [],
arbitraryProperty: "arbitraryValue",
arbitraryMethod: () => {
return "arbitraryValue";
},
} as const;
});
const extInstance = extension()({ editor });
expect(extInstance.arbitraryProperty).toBe("arbitraryValue");
expect(extInstance.arbitraryMethod()).toBe("arbitraryValue");
// @ts-expect-error - this method takes no arguments
extInstance.arbitraryMethod(90);
// @ts-expect-error - this property is not defined
extInstance.nonExistentProperty = "newArbitraryValue";
});
it("allows arbitrary properties on an extension with options", () => {
const extension = createExtension((opts: ExtensionOptions<{ x: number }>) => {
expect(opts.options.x).toBe(1);
return {
key: "test",
prosemirrorPlugins: [],
arbitraryProperty: "arbitraryValue",
arbitraryMethod: () => {
return "arbitraryValue";
},
} as const;
});
const extInstance = extension({ x: 1 })({ editor });
expect(extInstance.arbitraryProperty).toBe("arbitraryValue");
// @ts-expect-error - this method takes no arguments
extInstance.arbitraryMethod(90);
// @ts-expect-error - this property is not defined
extInstance.nonExistentProperty = "newArbitraryValue";
});