Testing SlateJS (0.50+) code

test utlities

  • packages you need to install: slate slate-hyperscript slate-react jest @testing-library/react (testingLib is optional)
1// /test/jsx.ts
2import { createHyperscript } from "slate-hyperscript"
3import { options } from "../src/options"
4import { createText } from "./hyperscript/creators"
5
6declare global {
7 namespace JSX {
8 interface IntrinsicElements {
9 [key: string]: any
10 editor: any
11 inline: any
12 htext: any
13 }
14 }
15}
16
17export const jsx = createHyperscript({
18 elements: {
19 hp: { type: "paragraph" },
20 // hmention: {type: options.mention.type},
21 hblockquote: { type: "block_quote" },
22 hcode: { type: "code" },
23 ha: { type: "link" },
24 himg: { type: "img" },
25 hul: { type: "ul_list" },
26 hol: { type: "ol_list" },
27 hli: { type: "list_item" },
28 hh1: { type: "heading_1" },
29 hh2: { type: "heading_2" },
30 hh3: { type: "heading_3" },
31 hh4: { type: "heading_4" },
32 hh5: { type: "heading_5" },
33 hh6: { type: "heading_6" },
34 inline: { inline: true },
35 },
36 creators: {
37 htext: createText,
38 },
39})
  • you can also create an options attribute to pass all the types to the createHyperscript elements (checkout this example)
1// /test/hyperscript/creators.ts

Testing plugins

WIP

Testing keaboard actions

WIP

© 2022, Powered by Gatsby