@@ -7,10 +7,11 @@ vi.mock("./lib/load-formbricks", () => ({
77
88import formbricks from "./index" ;
99import * as loadFormbricksModule from "./lib/load-formbricks" ;
10+ import { TFormbricks } from "./types/formbricks" ;
1011
1112// Get the mocked function
1213const mockLoadFormbricksToProxy = vi . mocked (
13- loadFormbricksModule . loadFormbricksToProxy
14+ loadFormbricksModule . loadFormbricksToProxy ,
1415) ;
1516
1617describe ( "formbricks proxy" , ( ) => {
@@ -60,7 +61,7 @@ describe("formbricks proxy", () => {
6061 expect ( mockLoadFormbricksToProxy ) . toHaveBeenCalledWith (
6162 "setAttribute" ,
6263 key ,
63- value
64+ value ,
6465 ) ;
6566 } ) ;
6667
@@ -74,7 +75,7 @@ describe("formbricks proxy", () => {
7475
7576 expect ( mockLoadFormbricksToProxy ) . toHaveBeenCalledWith (
7677 "setAttributes" ,
77- attributes
78+ attributes ,
7879 ) ;
7980 } ) ;
8081
@@ -85,7 +86,7 @@ describe("formbricks proxy", () => {
8586
8687 expect ( mockLoadFormbricksToProxy ) . toHaveBeenCalledWith (
8788 "setLanguage" ,
88- language
89+ language ,
8990 ) ;
9091 } ) ;
9192
@@ -107,7 +108,7 @@ describe("formbricks proxy", () => {
107108 await formbricks . registerRouteChange ( ) ;
108109
109110 expect ( mockLoadFormbricksToProxy ) . toHaveBeenCalledWith (
110- "registerRouteChange"
111+ "registerRouteChange" ,
111112 ) ;
112113 } ) ;
113114
@@ -121,7 +122,7 @@ describe("formbricks proxy", () => {
121122 } ,
122123 } ;
123124
124- await ( formbricks as any ) . init ( initConfig ) ;
125+ await formbricks . init ( initConfig ) ;
125126
126127 expect ( mockLoadFormbricksToProxy ) . toHaveBeenCalledWith ( "init" , initConfig ) ;
127128 } ) ;
@@ -136,32 +137,30 @@ describe("formbricks proxy", () => {
136137 } ,
137138 } ;
138139
139- // Cast to any to access the extended track method with properties
140- await ( formbricks as any ) . track ( trackCode , properties ) ;
140+ await formbricks . track ( trackCode , properties ) ;
141141
142142 expect ( mockLoadFormbricksToProxy ) . toHaveBeenCalledWith (
143143 "track" ,
144144 trackCode ,
145- properties
145+ properties ,
146146 ) ;
147147 } ) ;
148148
149149 test ( "should handle any method call through the proxy" , async ( ) => {
150- const customMethod = "customMethod " ;
151- const args = [ "arg1" , "arg2" , { key : "value" } ] ;
150+ const customMethod : keyof TFormbricks = "track " ;
151+ const args = [ "arg1" ] ;
152152
153- // Cast to any to call a method that doesn't exist in the type definition
154- await ( formbricks as any ) [ customMethod ] ( ...args ) ;
153+ await formbricks [ customMethod ] ( args [ 0 ] ) ;
155154
156155 expect ( mockLoadFormbricksToProxy ) . toHaveBeenCalledWith (
157156 customMethod ,
158- ... args
157+ args [ 0 ] ,
159158 ) ;
160159 } ) ;
161160
162161 test ( "should return the result of loadFormbricksToProxy calls" , async ( ) => {
163162 const mockResult = "test-result" ;
164- mockLoadFormbricksToProxy . mockResolvedValue ( mockResult as any ) ;
163+ mockLoadFormbricksToProxy . mockResolvedValue ( mockResult as unknown as void ) ;
165164
166165 const result = await formbricks . setEmail ( "test@example.com" ) ;
167166
@@ -173,7 +172,7 @@ describe("formbricks proxy", () => {
173172 mockLoadFormbricksToProxy . mockRejectedValue ( error ) ;
174173
175174 await expect ( formbricks . setEmail ( "test@example.com" ) ) . rejects . toThrow (
176- "Test error"
175+ "Test error" ,
177176 ) ;
178177 } ) ;
179178
@@ -190,12 +189,12 @@ describe("formbricks proxy", () => {
190189 expect ( mockLoadFormbricksToProxy ) . toHaveBeenCalledTimes ( 4 ) ;
191190 expect ( mockLoadFormbricksToProxy ) . toHaveBeenCalledWith (
192191 "setEmail" ,
193- "test@example.com"
192+ "test@example.com" ,
194193 ) ;
195194 expect ( mockLoadFormbricksToProxy ) . toHaveBeenCalledWith (
196195 "setAttribute" ,
197196 "userId" ,
198- "user123"
197+ "user123" ,
199198 ) ;
200199 expect ( mockLoadFormbricksToProxy ) . toHaveBeenCalledWith ( "track" , "event1" ) ;
201200 expect ( mockLoadFormbricksToProxy ) . toHaveBeenCalledWith ( "setLanguage" , "en" ) ;
@@ -226,7 +225,7 @@ describe("proxy behavior", () => {
226225
227226 expect ( mockLoadFormbricksToProxy ) . toHaveBeenCalledWith (
228227 "setUserId" ,
229- "user123"
228+ "user123" ,
230229 ) ;
231230 } ) ;
232231
@@ -236,7 +235,7 @@ describe("proxy behavior", () => {
236235 expect ( mockLoadFormbricksToProxy ) . toHaveBeenCalledWith (
237236 "setAttribute" ,
238237 "key" ,
239- "value"
238+ "value" ,
240239 ) ;
241240 } ) ;
242241
@@ -250,7 +249,7 @@ describe("proxy behavior", () => {
250249
251250 expect ( mockLoadFormbricksToProxy ) . toHaveBeenCalledWith (
252251 "setup" ,
253- setupConfig
252+ setupConfig ,
254253 ) ;
255254 } ) ;
256255} ) ;
@@ -264,15 +263,15 @@ describe("type safety", () => {
264263 test ( "should maintain type safety for known methods" , ( ) => {
265264 // These should compile without errors due to proper typing
266265 const testTypeSafety = ( ) => {
267- formbricks . setup ( { environmentId : "env" , appUrl : "url" } ) ;
268- formbricks . track ( "event" ) ;
269- formbricks . setEmail ( "email" ) ;
270- formbricks . setAttribute ( "key" , "value" ) ;
271- formbricks . setAttributes ( { key : "value" } ) ;
272- formbricks . setLanguage ( "en" ) ;
273- formbricks . setUserId ( "user" ) ;
274- formbricks . logout ( ) ;
275- formbricks . registerRouteChange ( ) ;
266+ void formbricks . setup ( { environmentId : "env" , appUrl : "url" } ) ;
267+ void formbricks . track ( "event" ) ;
268+ void formbricks . setEmail ( "email" ) ;
269+ void formbricks . setAttribute ( "key" , "value" ) ;
270+ void formbricks . setAttributes ( { key : "value" } ) ;
271+ void formbricks . setLanguage ( "en" ) ;
272+ void formbricks . setUserId ( "user" ) ;
273+ void formbricks . logout ( ) ;
274+ void formbricks . registerRouteChange ( ) ;
276275 } ;
277276
278277 expect ( testTypeSafety ) . not . toThrow ( ) ;
0 commit comments