History

Use Vitest assert API in keybindings tests

- Replace `expect` assertions with `assert` in server and contracts keybinding tests - Keep existing coverage while standardizing assertion style

Julius Marminge committed 9 months ago

Commit 3e1bfcb1 parent 3b2f5592 files · +21 −19Browse files

Unified · Split

2 files
  1. apps/server/src/keybindings.test.ts +8 −8
  2. packages/contracts/src/keybindings.test.ts +13 −11
apps/server/src/keybindings.test.ts+8−8
@@ -1,10 +1,10 @@
1−import { describe, expect, it } from "vitest";
1+import { assert, describe, it } from "vitest";
22
33 import { compileResolvedKeybindingRule, parseKeybindingShortcut } from "./keybindings";
44
55 describe("server keybindings", () => {
66 it("parses shortcuts including plus key", () => {
7− expect(parseKeybindingShortcut("mod+j")).toEqual({
7+ assert.deepEqual(parseKeybindingShortcut("mod+j"), {
88 key: "j",
99 metaKey: false,
1010 ctrlKey: false,
@@ -12,7 +12,7 @@ describe("server keybindings", () => { · 1 unmodified line
1212 altKey: false,
1313 modKey: true,
1414 });
15− expect(parseKeybindingShortcut("mod++")).toEqual({
15+ assert.deepEqual(parseKeybindingShortcut("mod++"), {
1616 key: "+",
1717 metaKey: false,
1818 ctrlKey: false,
@@ -29,7 +29,7 @@ describe("server keybindings", () => { · 10 unmodified lines
2929 when: "terminalOpen && !terminalFocus",
3030 });
3131
32− expect(compiled).toEqual({
32+ assert.deepEqual(compiled, {
3333 key: "mod+d",
3434 command: "terminal.split",
3535 when: "terminalOpen && !terminalFocus",
@@ -53,19 +53,19 @@ describe("server keybindings", () => { · 17 unmodified lines
5353 });
5454
5555 it("rejects invalid rules", () => {
56− expect(
56+ assert.isNull(
5757 compileResolvedKeybindingRule({
5858 key: "mod+shift+d+o",
5959 command: "terminal.new",
6060 }),
61− ).toBeNull();
61+ );
6262
63− expect(
63+ assert.isNull(
6464 compileResolvedKeybindingRule({
6565 key: "mod+d",
6666 command: "terminal.split",
6767 when: "terminalFocus && (",
6868 }),
69− ).toBeNull();
69+ );
7070 });
7171 });
packages/contracts/src/keybindings.test.ts+13−11
@@ -1,4 +1,4 @@
1−import { describe, expect, it } from "vitest";
1+import { assert, describe, it } from "vitest";
22
33 import {
44 keybindingRuleSchema,
@@ -13,16 +13,18 @@ describe("keybindings contracts", () => { · 8 unmodified lines
1313 key: "mod+j",
1414 command: "terminal.toggle",
1515 });
16− expect(parsed.command).toBe("terminal.toggle");
16+ assert.strictEqual(parsed.command, "terminal.toggle");
1717 });
1818
1919 it("rejects invalid command values", () => {
20− expect(() =>
21− keybindingRuleSchema.parse({
22− key: "mod+j",
23− command: "invalid.command" as unknown as "terminal.toggle",
24− }),
25− ).toThrow();
20+ assert.throws(() =>
21+ keybindingRuleSchema.parse(
22+ {
23+ key: "mod+j",
24+ command: "invalid.command" as unknown as "terminal.toggle",
25+ },
26+ ),
27+ );
2628 });
2729
2830 it("parses keybindings array payload", () => {
@@ -30,7 +32,7 @@ describe("keybindings contracts", () => { · 1 unmodified line
3032 { key: "mod+j", command: "terminal.toggle" },
3133 { key: "mod+d", command: "terminal.split", when: "terminalFocus" },
3234 ]);
33− expect(parsed).toHaveLength(2);
35+ assert.lengthOf(parsed, 2);
3436 });
3537
3638 it("parses resolved keybinding rules", () => {
@@ -55,7 +57,7 @@ describe("keybindings contracts", () => { · 18 unmodified lines
5557 },
5658 },
5759 });
58− expect(parsed.shortcut.key).toBe("d");
60+ assert.strictEqual(parsed.shortcut.key, "d");
5961 });
6062
6163 it("parses resolved keybindings arrays", () => {
@@ -73,6 +75,6 @@ describe("keybindings contracts", () => { · 11 unmodified lines
7375 },
7476 },
7577 ]);
76− expect(parsed).toHaveLength(1);
78+ assert.lengthOf(parsed, 1);
7779 });
7880 });

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t