Skip to content

Commit 58cb1b4

Browse files
committed
Fix ApiClient constructor mocks in tests
1 parent 1605a9f commit 58cb1b4

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

packages/react-native/src/lib/environment/tests/state.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import type { TEnvironmentState } from "@/types/config";
2222

2323
// Mock the FormbricksAPI so we can control environment.getState
2424
vi.mock("@/lib/common/api", () => ({
25-
ApiClient: vi.fn().mockImplementation(() => {
25+
ApiClient: vi.fn().mockImplementation(function MockApiClient() {
2626
return { getEnvironmentState: vi.fn() };
2727
}),
2828
}));
@@ -70,7 +70,7 @@ describe("environment/state.ts", () => {
7070
describe("fetchEnvironmentState()", () => {
7171
test("returns ok(...) with environment state", async () => {
7272
// Setup mock
73-
(ApiClient as unknown as Mock).mockImplementationOnce(() => {
73+
(ApiClient as unknown as Mock).mockImplementationOnce(function MockApiClient() {
7474
return {
7575
getEnvironmentState: vi.fn().mockResolvedValue({
7676
ok: true,
@@ -103,7 +103,7 @@ describe("environment/state.ts", () => {
103103
message: "Access denied",
104104
};
105105

106-
(ApiClient as unknown as Mock).mockImplementationOnce(() => {
106+
(ApiClient as unknown as Mock).mockImplementationOnce(function MockApiClient() {
107107
return {
108108
getEnvironmentState: vi.fn().mockResolvedValue({
109109
ok: false,
@@ -131,7 +131,7 @@ describe("environment/state.ts", () => {
131131
responseMessage: "Network fail",
132132
};
133133

134-
(ApiClient as unknown as Mock).mockImplementationOnce(() => {
134+
(ApiClient as unknown as Mock).mockImplementationOnce(function MockApiClient() {
135135
return {
136136
getEnvironmentState: vi.fn().mockRejectedValue(mockNetworkError),
137137
};
@@ -208,7 +208,7 @@ describe("environment/state.ts", () => {
208208

209209
mockRNConfig.mockReturnValue(mockConfig as unknown as Promise<RNConfig>);
210210

211-
(ApiClient as Mock).mockImplementation(() => {
211+
(ApiClient as Mock).mockImplementation(function MockApiClient() {
212212
return {
213213
getEnvironmentState: vi.fn().mockResolvedValue({
214214
ok: true,
@@ -244,7 +244,7 @@ describe("environment/state.ts", () => {
244244
mockRNConfig.mockReturnValue(mockConfig as unknown as Promise<RNConfig>);
245245

246246
// Mock API to throw an error
247-
(ApiClient as Mock).mockImplementation(() => {
247+
(ApiClient as Mock).mockImplementation(function MockApiClient() {
248248
return {
249249
getEnvironmentState: vi
250250
.fn()
@@ -276,7 +276,7 @@ describe("environment/state.ts", () => {
276276

277277
mockRNConfig.mockReturnValue(mockConfig as unknown as Promise<RNConfig>);
278278

279-
const apiMock = vi.fn().mockImplementation(() => {
279+
const apiMock = vi.fn().mockImplementation(function MockApiClient() {
280280
return { getEnvironmentState: vi.fn() };
281281
});
282282

packages/react-native/src/lib/user/tests/update.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ vi.mock("@/lib/common/utils", () => ({
3434
}));
3535

3636
vi.mock("@/lib/common/api", () => ({
37-
ApiClient: vi.fn().mockImplementation(() => {
37+
ApiClient: vi.fn().mockImplementation(function MockApiClient() {
3838
return { createOrUpdateUser: vi.fn() };
3939
}),
4040
}));
@@ -57,7 +57,7 @@ describe("sendUpdatesToBackend", () => {
5757
},
5858
};
5959

60-
(ApiClient as Mock).mockImplementation(() => {
60+
(ApiClient as Mock).mockImplementation(function MockApiClient() {
6161
return { createOrUpdateUser: vi.fn().mockResolvedValue(mockResponse) };
6262
});
6363

@@ -82,7 +82,7 @@ describe("sendUpdatesToBackend", () => {
8282
attributes: mockAttributes,
8383
};
8484

85-
(ApiClient as Mock).mockImplementation(() => {
85+
(ApiClient as Mock).mockImplementation(function MockApiClient() {
8686
return {
8787
createOrUpdateUser: vi.fn().mockResolvedValue({
8888
ok: false,
@@ -116,7 +116,7 @@ describe("sendUpdatesToBackend", () => {
116116
attributes: { plan: "premium" },
117117
};
118118

119-
(ApiClient as Mock).mockImplementation(() => {
119+
(ApiClient as Mock).mockImplementation(function MockApiClient() {
120120
return {
121121
createOrUpdateUser: vi
122122
.fn()
@@ -169,7 +169,7 @@ describe("sendUpdates", () => {
169169
},
170170
};
171171

172-
(ApiClient as Mock).mockImplementation(() => {
172+
(ApiClient as Mock).mockImplementation(function MockApiClient() {
173173
return { createOrUpdateUser: vi.fn().mockResolvedValue(mockResponse) };
174174
});
175175

@@ -193,7 +193,7 @@ describe("sendUpdates", () => {
193193
},
194194
};
195195

196-
(ApiClient as Mock).mockImplementation(() => {
196+
(ApiClient as Mock).mockImplementation(function MockApiClient() {
197197
return {
198198
createOrUpdateUser: vi.fn().mockResolvedValue(mockErrorResponse),
199199
};
@@ -224,7 +224,7 @@ describe("sendUpdates", () => {
224224
},
225225
};
226226

227-
(ApiClient as Mock).mockImplementation(() => {
227+
(ApiClient as Mock).mockImplementation(function MockApiClient() {
228228
return { createOrUpdateUser: vi.fn().mockResolvedValue(mockResponse) };
229229
});
230230

@@ -261,7 +261,7 @@ describe("sendUpdates", () => {
261261
},
262262
};
263263

264-
(ApiClient as Mock).mockImplementation(() => {
264+
(ApiClient as Mock).mockImplementation(function MockApiClient() {
265265
return { createOrUpdateUser: vi.fn().mockResolvedValue(mockResponse) };
266266
});
267267

@@ -278,7 +278,7 @@ describe("sendUpdates", () => {
278278
});
279279

280280
test("handles unexpected errors", async () => {
281-
(ApiClient as Mock).mockImplementation(() => {
281+
(ApiClient as Mock).mockImplementation(function MockApiClient() {
282282
return {
283283
createOrUpdateUser: vi
284284
.fn()

0 commit comments

Comments
 (0)