Skip to content

Commit e4f88a9

Browse files
committed
2 parents b4f7557 + c2fa7ec commit e4f88a9

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

course-matrix/frontend/__tests__/unit-tests/useClickOutside.test.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,16 @@ describe("useClickOutside", () => {
8585

8686
test("should remove event listener when isActive changes from true to false", () => {
8787
const { rerender } = render(
88-
<TestComponent isActive={true} onClickOutside={mockOnClickOutside} />
88+
<TestComponent isActive={true} onClickOutside={mockOnClickOutside} />,
89+
);
90+
91+
rerender(
92+
<TestComponent isActive={false} onClickOutside={mockOnClickOutside} />,
93+
);
94+
95+
expect(document.removeEventListener).toHaveBeenCalledWith(
96+
"mousedown",
97+
expect.any(Function),
8998
);
9099

91100
rerender(
@@ -100,7 +109,7 @@ describe("useClickOutside", () => {
100109

101110
test("should call onClickOutside when clicking outside the ref element", () => {
102111
const { getByTestId } = render(
103-
<TestComponent isActive={true} onClickOutside={mockOnClickOutside} />
112+
<TestComponent isActive={true} onClickOutside={mockOnClickOutside} />,
104113
);
105114

106115
// Simulate clicking outside
@@ -111,7 +120,7 @@ describe("useClickOutside", () => {
111120

112121
test("should not call onClickOutside when clicking inside the ref element", () => {
113122
const { getByTestId } = render(
114-
<TestComponent isActive={true} onClickOutside={mockOnClickOutside} />
123+
<TestComponent isActive={true} onClickOutside={mockOnClickOutside} />,
115124
);
116125

117126
// Simulate clicking inside
@@ -137,7 +146,7 @@ describe("useClickOutside", () => {
137146

138147
test("should clean up event listener when unmounting", () => {
139148
const { unmount } = render(
140-
<TestComponent isActive={true} onClickOutside={mockOnClickOutside} />
149+
<TestComponent isActive={true} onClickOutside={mockOnClickOutside} />,
141150
);
142151

143152
unmount();
@@ -148,7 +157,7 @@ describe("useClickOutside", () => {
148157
test("should re-attach event listener when dependencies change", () => {
149158
const newMockCallback = jest.fn();
150159
const { rerender } = render(
151-
<TestComponent isActive={true} onClickOutside={mockOnClickOutside} />
160+
<TestComponent isActive={true} onClickOutside={mockOnClickOutside} />,
152161
);
153162

154163
// First, verify initial setup

course-matrix/frontend/__tests__/unit-tests/useDebounce.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe("useDebounceValue", () => {
2929
const initialValue = "initial";
3030
const { result, rerender } = renderHook(
3131
({ value, interval }) => useDebounceValue(value, interval),
32-
{ initialProps: { value: initialValue, interval: 500 } }
32+
{ initialProps: { value: initialValue, interval: 500 } },
3333
);
3434

3535
expect(result.current).toBe(initialValue);
@@ -62,7 +62,7 @@ describe("useDebounceValue", () => {
6262
const initialValue = "initial";
6363
const { result, rerender } = renderHook(
6464
({ value, interval }) => useDebounceValue(value, interval),
65-
{ initialProps: { value: initialValue, interval: 500 } }
65+
{ initialProps: { value: initialValue, interval: 500 } },
6666
);
6767

6868
// Change the value once
@@ -100,7 +100,7 @@ describe("useDebounceValue", () => {
100100
const initialValue = "initial";
101101
const { result, rerender } = renderHook(
102102
({ value, interval }) => useDebounceValue(value, interval),
103-
{ initialProps: { value: initialValue, interval: 500 } }
103+
{ initialProps: { value: initialValue, interval: 500 } },
104104
);
105105

106106
// Change value and interval
@@ -128,7 +128,7 @@ describe("useDebounceValue", () => {
128128
const initialObject = { name: "John" };
129129
const { result: objectResult, rerender: objectRerender } = renderHook(
130130
({ value, interval }) => useDebounceValue(value, interval),
131-
{ initialProps: { value: initialObject, interval: 200 } }
131+
{ initialProps: { value: initialObject, interval: 200 } },
132132
);
133133

134134
const newObject = { name: "Jane" };
@@ -143,7 +143,7 @@ describe("useDebounceValue", () => {
143143
// Test with number
144144
const { result: numberResult, rerender: numberRerender } = renderHook(
145145
({ value, interval }) => useDebounceValue(value, interval),
146-
{ initialProps: { value: 1, interval: 200 } }
146+
{ initialProps: { value: 1, interval: 200 } },
147147
);
148148

149149
numberRerender({ value: 2, interval: 200 });

0 commit comments

Comments
 (0)