Skip to content

Commit 1783d21

Browse files
committed
Use toHaveBeenCalledTimes and toHaveBeenNthCalledWith
1 parent 5d363ef commit 1783d21

File tree

11 files changed

+284
-276
lines changed

11 files changed

+284
-276
lines changed

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
"@babel/core": "^7.28.4",
3737
"@babel/preset-env": "^7.28.3",
3838
"@babel/preset-typescript": "^7.27.1",
39-
"@eslint/js": "^9.36.0",
39+
"@eslint/js": "^9.37.0",
4040
"@playwright/test": "^1.55.1",
4141
"@rollup/plugin-babel": "^6.0.4",
42-
"@rollup/plugin-node-resolve": "^16.0.1",
42+
"@rollup/plugin-node-resolve": "^16.0.2",
4343
"@rollup/plugin-terser": "^0.4.4",
4444
"@testing-library/dom": "^10.4.1",
4545
"@testing-library/jest-dom": "^6.9.1",
@@ -49,13 +49,13 @@
4949
"@types/jquery": "^3.5.33",
5050
"@types/node": "^24.6.2",
5151
"@vitest/coverage-istanbul": "^3.2.4",
52-
"@vitest/eslint-plugin": "^1.3.13",
52+
"@vitest/eslint-plugin": "^1.3.16",
5353
"autoprefixer": "^10.4.21",
5454
"babel-plugin-istanbul": "^7.0.1",
55-
"eslint": "^9.36.0",
55+
"eslint": "^9.37.0",
5656
"eslint-plugin-import": "^2.32.0",
5757
"eslint-plugin-jest-dom": "^5.5.0",
58-
"eslint-plugin-perfectionist": "^4.15.0",
58+
"eslint-plugin-perfectionist": "^4.15.1",
5959
"eslint-plugin-playwright": "^2.2.2",
6060
"eslint-plugin-testing-library": "^7.11.0",
6161
"givens": "^1.3.9",
@@ -71,7 +71,7 @@
7171
"postcss-load-config": "^6.0.1",
7272
"postcss-nested": "^7.0.2",
7373
"prettier": "^3.6.2",
74-
"rollup": "^4.52.3",
74+
"rollup": "^4.52.4",
7575
"rollup-plugin-serve": "^3.0.0",
7676
"tslib": "^2.8.1",
7777
"typescript": "^5.9.3",

pnpm-lock.yaml

Lines changed: 229 additions & 220 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/test/dataLoader.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe("loadFromUrl", () => {
6363
dataLoader.loadFromUrl({ dataType: "text", url: "/test" }, null, null);
6464

6565
await waitFor(() => {
66-
expect(loadData).toHaveBeenCalledWith({ key1: "value1" }, null);
66+
expect(loadData).toHaveBeenCalledExactlyOnceWith({ key1: "value1" }, null);
6767
});
6868
});
6969
});

src/test/dragAndDropHandler/index.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ describe("DragAndDropHandler", () => {
231231
expect(dragAndDropHandler.mouseCapture(positionInfo)).toBeTrue();
232232
expect(dragAndDropHandler.currentItem?.node).toBe(node1);
233233

234-
expect(onIsMoveHandle).toHaveBeenCalledWith(expect.anything());
234+
expect(onIsMoveHandle).toHaveBeenCalledExactlyOnceWith(expect.anything());
235235
});
236236

237237
it("doesn't capture the node when onIsMoveHandle returns false", () => {
@@ -257,7 +257,7 @@ describe("DragAndDropHandler", () => {
257257
expect(dragAndDropHandler.mouseCapture(positionInfo)).toBeNull();
258258
expect(dragAndDropHandler.currentItem).toBeNull();
259259

260-
expect(onIsMoveHandle).toHaveBeenCalledWith(expect.anything());
260+
expect(onIsMoveHandle).toHaveBeenCalledExactlyOnceWith(expect.anything());
261261
});
262262

263263
it("doesn't capture when onCanMove returns false", () => {
@@ -287,7 +287,7 @@ describe("DragAndDropHandler", () => {
287287
expect(dragAndDropHandler.mouseCapture(positionInfo)).toBeFalse();
288288
expect(dragAndDropHandler.currentItem).toBeNull();
289289

290-
expect(onCanMove).toHaveBeenCalledWith(node2);
290+
expect(onCanMove).toHaveBeenCalledExactlyOnceWith(node2);
291291
});
292292

293293
it("captures when onCanMove returns true", () => {
@@ -317,7 +317,7 @@ describe("DragAndDropHandler", () => {
317317
expect(dragAndDropHandler.mouseCapture(positionInfo)).toBeTrue();
318318
expect(dragAndDropHandler.currentItem?.node).toStrictEqual(node2);
319319

320-
expect(onCanMove).toHaveBeenCalledWith(node2);
320+
expect(onCanMove).toHaveBeenCalledExactlyOnceWith(node2);
321321
});
322322
});
323323

@@ -465,7 +465,7 @@ describe("DragAndDropHandler", () => {
465465
// Stop
466466
dragAndDropHandler.mouseStop(dragPositionInfo);
467467

468-
expect(triggerEvent).toHaveBeenCalledWith(
468+
expect(triggerEvent).toHaveBeenCalledExactlyOnceWith(
469469
"tree.move",
470470
expect.objectContaining({
471471
move_info: {
@@ -524,7 +524,7 @@ describe("DragAndDropHandler", () => {
524524
// Stop
525525
dragAndDropHandler.mouseStop(dragPositionInfo);
526526

527-
expect(mockMoveNode).toHaveBeenCalledWith(node1, node2, "inside");
527+
expect(mockMoveNode).toHaveBeenCalledExactlyOnceWith(node1, node2, "inside");
528528
});
529529

530530
it("calls onDragStop when there is no hovered area", () => {
@@ -573,7 +573,7 @@ describe("DragAndDropHandler", () => {
573573
target: document.body,
574574
});
575575

576-
expect(onDragStop).toHaveBeenCalledWith(node1, originalEvent);
576+
expect(onDragStop).toHaveBeenCalledExactlyOnceWith(node1, originalEvent);
577577
});
578578
});
579579

@@ -790,7 +790,7 @@ describe("DragAndDropHandler", () => {
790790
// Move mouse
791791
dragAndDropHandler.mouseDrag(positionInfoForDragging);
792792

793-
expect(onDragMove).toHaveBeenCalledWith(
793+
expect(onDragMove).toHaveBeenCalledExactlyOnceWith(
794794
node1,
795795
positionInfoForDragging.originalEvent,
796796
);
@@ -832,7 +832,7 @@ describe("DragAndDropHandler", () => {
832832
target: node2.element as HTMLElement,
833833
});
834834

835-
expect(onCanMoveTo).toHaveBeenCalledWith(node1, node2, "inside");
835+
expect(onCanMoveTo).toHaveBeenCalledExactlyOnceWith(node1, node2, "inside");
836836

837837
// Still sets hoveredArea to the new node
838838
expect(dragAndDropHandler.hoveredArea?.node).toStrictEqual(node2);
@@ -886,7 +886,7 @@ describe("DragAndDropHandler", () => {
886886

887887
vi.advanceTimersByTime(100);
888888

889-
expect(openNode).toHaveBeenCalledWith(
889+
expect(openNode).toHaveBeenCalledExactlyOnceWith(
890890
node2,
891891
false,
892892
expect.toBeFunction(),

src/test/jqTree/events.test.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe("events", () => {
4646

4747
await userEvent.click(given.titleSpan);
4848

49-
expect(onClick).toHaveBeenCalledWith(
49+
expect(onClick).toHaveBeenCalledExactlyOnceWith(
5050
expect.objectContaining({ node: given.node1 }),
5151
);
5252
});
@@ -79,7 +79,7 @@ describe("events", () => {
7979
target: given.titleSpan,
8080
});
8181

82-
expect(onContextMenu).toHaveBeenCalledWith(
82+
expect(onContextMenu).toHaveBeenCalledExactlyOnceWith(
8383
expect.objectContaining({ node: given.node1 }),
8484
);
8585
});
@@ -109,7 +109,7 @@ describe("events", () => {
109109

110110
await userEvent.dblClick(given.titleSpan);
111111

112-
expect(onDoubleClick).toHaveBeenCalledWith(
112+
expect(onDoubleClick).toHaveBeenCalledExactlyOnceWith(
113113
expect.objectContaining({ node: given.node1 }),
114114
);
115115
});
@@ -131,7 +131,7 @@ describe("events", () => {
131131
data: exampleData,
132132
});
133133

134-
expect(onInit).toHaveBeenCalledWith(expect.anything());
134+
expect(onInit).toHaveBeenCalledExactlyOnceWith(expect.anything());
135135
});
136136
});
137137

@@ -155,7 +155,7 @@ describe("events", () => {
155155
given.$tree.tree({ dataUrl: "/tree/" });
156156

157157
await waitFor(() => {
158-
expect(onInit).toHaveBeenCalledWith(expect.anything());
158+
expect(onInit).toHaveBeenCalledExactlyOnceWith(expect.anything());
159159
});
160160
});
161161
});
@@ -175,7 +175,7 @@ describe("events", () => {
175175

176176
given.$tree.tree({ data: exampleData });
177177

178-
expect(onLoadData).toHaveBeenCalledWith(
178+
expect(onLoadData).toHaveBeenCalledExactlyOnceWith(
179179
expect.objectContaining({ tree_data: exampleData }),
180180
);
181181
});
@@ -208,7 +208,7 @@ describe("events", () => {
208208

209209
await userEvent.click(given.titleSpan);
210210

211-
expect(onSelect).toHaveBeenCalledWith(
211+
expect(onSelect).toHaveBeenCalledExactlyOnceWith(
212212
expect.objectContaining({
213213
deselected_node: null,
214214
node: given.node1,
@@ -227,7 +227,7 @@ describe("events", () => {
227227

228228
await userEvent.click(given.titleSpan);
229229

230-
expect(onSelect).toHaveBeenCalledWith(
230+
expect(onSelect).toHaveBeenCalledExactlyOnceWith(
231231
expect.objectContaining({
232232
node: null,
233233
previous_node: given.node1,
@@ -259,7 +259,7 @@ describe("events", () => {
259259
$tree.tree({ dataUrl: "/tree/" });
260260

261261
await waitFor(() => {
262-
expect(onLoading).toHaveBeenCalledWith(
262+
expect(onLoading).toHaveBeenCalledExactlyOnceWith(
263263
expect.objectContaining({
264264
isLoading: true,
265265
node: null,
@@ -298,11 +298,7 @@ describe("events", () => {
298298
$tree.tree({ dataUrl: "/tree/", onLoading });
299299

300300
await waitFor(() => {
301-
expect(onLoading).toHaveBeenCalledWith(false, null, $tree);
302-
});
303-
304-
await waitFor(() => {
305-
expect(onLoading).toHaveBeenCalledWith(false, null, $tree);
301+
expect(onLoading).toHaveBeenNthCalledWith(2, false, null, $tree);
306302
});
307303
});
308304
});

src/test/jqTree/methods.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@ describe("methods", () => {
10941094
given.$tree.tree("openNode", given.node1, onFinished);
10951095

10961096
await waitFor(() => {
1097-
expect(onFinished).toHaveBeenCalledWith(given.node1);
1097+
expect(onFinished).toHaveBeenCalledExactlyOnceWith(given.node1);
10981098
});
10991099
});
11001100

@@ -1241,7 +1241,7 @@ describe("methods", () => {
12411241
given.$tree.tree("reload", handleFinished);
12421242

12431243
await waitFor(() => {
1244-
expect(handleFinished).toHaveBeenCalledWith();
1244+
expect(handleFinished).toHaveBeenCalledExactlyOnceWith();
12451245
});
12461246

12471247
expect(given.$tree).toHaveTreeStructure([

src/test/jqTree/options.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ describe("options", () => {
304304
await screen.findByText("node2");
305305

306306
expect(screen.queryByText("node1")).not.toBeInTheDocument();
307-
expect(dataFilter).toHaveBeenCalledWith(exampleData);
307+
expect(dataFilter).toHaveBeenCalledExactlyOnceWith(exampleData);
308308
});
309309
});
310310

@@ -552,7 +552,7 @@ describe("options", () => {
552552
});
553553

554554
await waitFor(() => {
555-
expect(onLoadFailed).toHaveBeenCalledWith(
555+
expect(onLoadFailed).toHaveBeenCalledExactlyOnceWith(
556556
expect.objectContaining({ status: 500 }),
557557
);
558558
});

src/test/mouseHandler.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe("handleClick", () => {
8181
const event = new MouseEvent("click", { bubbles: true });
8282
button.dispatchEvent(event);
8383

84-
expect(onClickButton).toHaveBeenCalledWith(node);
84+
expect(onClickButton).toHaveBeenCalledExactlyOnceWith(node);
8585
});
8686

8787
it("handles a click with an empty target", () => {
@@ -129,7 +129,7 @@ describe("handleContextmenu", () => {
129129
const event = new MouseEvent("contextmenu", { bubbles: true });
130130
nodeElement.dispatchEvent(event);
131131

132-
expect(triggerEvent).toHaveBeenCalledWith("tree.contextmenu", {
132+
expect(triggerEvent).toHaveBeenCalledExactlyOnceWith("tree.contextmenu", {
133133
click_event: event,
134134
node,
135135
});
@@ -198,7 +198,7 @@ describe("handleDblclick", () => {
198198
const event = new MouseEvent("dblclick", { bubbles: true });
199199
label.dispatchEvent(event);
200200

201-
expect(triggerEvent).toHaveBeenCalledWith("tree.dblclick", {
201+
expect(triggerEvent).toHaveBeenCalledExactlyOnceWith("tree.dblclick", {
202202
click_event: event,
203203
node,
204204
});
@@ -245,7 +245,7 @@ describe("touchStart", () => {
245245
});
246246
element.dispatchEvent(event);
247247

248-
expect(onMouseCapture).toHaveBeenCalledWith({
248+
expect(onMouseCapture).toHaveBeenCalledExactlyOnceWith({
249249
originalEvent: event,
250250
pageX: 0,
251251
pageY: 0,
@@ -336,7 +336,7 @@ describe("touchEnd", () => {
336336
});
337337
element.dispatchEvent(touchEndEvent);
338338

339-
expect(onMouseStop).toHaveBeenCalledWith({
339+
expect(onMouseStop).toHaveBeenCalledExactlyOnceWith({
340340
originalEvent: touchEndEvent,
341341
pageX: 0,
342342
pageY: 0,

src/test/saveStateHandler.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe("setInitialState", () => {
7272
});
7373
saveStateHandler.setInitialState({});
7474

75-
expect(removeFromSelection).toHaveBeenCalledWith(node);
75+
expect(removeFromSelection).toHaveBeenCalledExactlyOnceWith(node);
7676
});
7777
});
7878

@@ -106,7 +106,7 @@ describe("setInitialStateOnDemand", () => {
106106
vi.fn(),
107107
);
108108

109-
expect(openNode).toHaveBeenCalledWith(node, false);
109+
expect(openNode).toHaveBeenCalledExactlyOnceWith(node, false);
110110
});
111111

112112
it("selects a node and redraws the tree when the node id is in selected_node in the state", () => {
@@ -132,8 +132,8 @@ describe("setInitialStateOnDemand", () => {
132132
vi.fn(),
133133
);
134134

135-
expect(addToSelection).toHaveBeenCalledWith(node);
136-
expect(refreshElements).toHaveBeenCalledWith(null);
135+
expect(addToSelection).toHaveBeenCalledExactlyOnceWith(node);
136+
expect(refreshElements).toHaveBeenCalledExactlyOnceWith(null);
137137
});
138138

139139
it("opens nodes recursively", () => {

src/test/scrollHandler/containerScrollParent.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe("checkHorizontalScrolling", () => {
3535

3636
vi.advanceTimersByTime(50);
3737

38-
expect(scrollBy).toHaveBeenCalledWith({
38+
expect(scrollBy).toHaveBeenCalledExactlyOnceWith({
3939
behavior: "instant",
4040
left: -20,
4141
top: 0,
@@ -69,7 +69,7 @@ describe("checkHorizontalScrolling", () => {
6969

7070
vi.advanceTimersByTime(50);
7171

72-
expect(scrollBy).toHaveBeenCalledWith({
72+
expect(scrollBy).toHaveBeenCalledExactlyOnceWith({
7373
behavior: "instant",
7474
left: -20,
7575
top: 0,
@@ -110,7 +110,7 @@ describe("checkVerticalScrolling", () => {
110110

111111
vi.advanceTimersByTime(50);
112112

113-
expect(scrollBy).toHaveBeenCalledWith({
113+
expect(scrollBy).toHaveBeenCalledExactlyOnceWith({
114114
behavior: "instant",
115115
left: 0,
116116
top: -20,
@@ -144,7 +144,7 @@ describe("checkVerticalScrolling", () => {
144144

145145
vi.advanceTimersByTime(50);
146146

147-
expect(scrollBy).toHaveBeenCalledWith({
147+
expect(scrollBy).toHaveBeenCalledExactlyOnceWith({
148148
behavior: "instant",
149149
left: 0,
150150
top: -20,

0 commit comments

Comments
 (0)