-
Notifications
You must be signed in to change notification settings - Fork 754
Expand file tree
/
Copy pathserver-event-handlers.test.ts
More file actions
59 lines (53 loc) · 2 KB
/
Copy pathserver-event-handlers.test.ts
File metadata and controls
59 lines (53 loc) · 2 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
import { expect } from "@std/expect";
import { testPlugin } from "../test-utils.ts";
import * as testRule from "./server-event-handlers.ts";
const okCases = new Set<[filename: string, code: string]>([
["file:///foo.jsx", "<Foo onClick={() => {}} />"],
["file:///foo.jsx", "<button onClick={() => {}} />"],
["file:///foo.jsx", "<button onClick={function () {}} />"],
["file:///foo.jsx", "<button onclick={function () {}} />"],
["file:///foo.jsx", "<button onClick=\"console.log('hey')\" />"],
["file:///foo.jsx", '<button online="foo" />'],
["file:///foo.jsx", "<x-foo onClick=\"console.log('hey')\" />"],
[
"file:///routes/foo/(_islands)/foo.jsx",
"<button onClick={function () {}} />",
],
]);
const errCases = new Set<[file: string, code: string, range: [number, number]]>(
[
["file:///routes/index.tsx", "<button onClick={() => {}} />", [8, 26]],
["file:///routes/index.tsx", "<button onTouchMove={() => {}} />", [8, 30]],
[
"file:///routes/index.tsx",
`<button onTouchMove={"console.log('hey')"} />`,
[8, 42],
],
["file:///routes/index.tsx", "<foo-button foo={() => {}} />", [12, 26]],
["file:///routes/index.tsx", "<foo-button foo={function () {}} />", [
12,
32,
]],
],
);
Deno.test("fresh/server-event-handlers - ok", () => {
for (const [file, code] of okCases) {
const diagnostics = Deno.lint.runPlugin(testPlugin(testRule), file, code);
expect(diagnostics.length).toBe(0);
}
});
Deno.test("fresh/server-event-handlers - err", () => {
for (const [file, code, range] of errCases) {
const [d, ...rest] = Deno.lint.runPlugin(testPlugin(testRule), file, code);
expect(rest.length).toBe(0);
expect(d.fix).toEqual([]);
expect(d.range).toEqual(range);
expect(d.id).toBe("fresh/server-event-handlers");
expect(d.message).toBe(
"Server components cannot install client side event handlers.",
);
expect(d.hint).toBe(
"Remove this property or turn the enclosing component into an island",
);
}
});