@@ -86,7 +86,7 @@ const mockSetTimeoutImmediate = () => {
8686 }
8787
8888 return 1 ;
89- } ,
89+ }
9090 ) ;
9191 return originalSetTimeout ;
9292} ;
@@ -143,11 +143,42 @@ describe("load-formbricks", () => {
143143 src : `${ setupArgs . appUrl } /js/formbricks.umd.cjs` ,
144144 type : "text/javascript" ,
145145 async : true ,
146- } ) ,
146+ } )
147147 ) ;
148148 expect ( mockFormbricks . setup ) . toHaveBeenCalledWith ( setupArgs ) ;
149149 } ) ;
150150
151+ test ( "should handle setup call with a trailing slash in the appUrl" , async ( ) => {
152+ const validAppUrl = "https://app.formbricks.com" ;
153+ const invalidAppUrl = "https://app.formbricks.com/" ;
154+ const environmentId = "env123" ;
155+
156+ const invalidSetupArgs = {
157+ appUrl : invalidAppUrl ,
158+ environmentId,
159+ } ;
160+
161+ const validateSetupArgs = {
162+ appUrl : validAppUrl ,
163+ environmentId,
164+ } ;
165+
166+ const mockAppendChild = vi
167+ . spyOn ( document . head , "appendChild" )
168+ . mockImplementation ( createSuccessfulScriptMock ( ) ) ;
169+
170+ await loadFormbricksToProxy ( "setup" , invalidSetupArgs ) ;
171+
172+ expect ( mockAppendChild ) . toHaveBeenCalledWith (
173+ expect . objectContaining ( {
174+ src : `${ validAppUrl } /js/formbricks.umd.cjs` ,
175+ type : "text/javascript" ,
176+ async : true ,
177+ } )
178+ ) ;
179+ expect ( mockFormbricks . setup ) . toHaveBeenCalledWith ( validateSetupArgs ) ;
180+ } ) ;
181+
151182 test ( "should log error when appUrl is missing" , async ( ) => {
152183 const consoleSpy = createConsoleErrorSpy ( ) ;
153184
@@ -156,7 +187,7 @@ describe("load-formbricks", () => {
156187 } ) ;
157188
158189 expect ( consoleSpy ) . toHaveBeenCalledWith (
159- "🧱 Formbricks - Error: appUrl is required" ,
190+ "🧱 Formbricks - Error: appUrl is required"
160191 ) ;
161192 } ) ;
162193
@@ -168,7 +199,7 @@ describe("load-formbricks", () => {
168199 } ) ;
169200
170201 expect ( consoleSpy ) . toHaveBeenCalledWith (
171- "🧱 Formbricks - Error: environmentId is required" ,
202+ "🧱 Formbricks - Error: environmentId is required"
172203 ) ;
173204 } ) ;
174205
@@ -199,15 +230,15 @@ describe("load-formbricks", () => {
199230 } ;
200231
201232 vi . spyOn ( document . head , "appendChild" ) . mockImplementation (
202- createTimeoutScriptMock ( ) ,
233+ createTimeoutScriptMock ( )
203234 ) ;
204235
205236 const originalSetTimeout = mockSetTimeoutImmediate ( ) ;
206237
207238 await loadFormbricksToProxy ( "setup" , setupArgs ) ;
208239
209240 expect ( consoleSpy ) . toHaveBeenCalledWith (
210- "🧱 Formbricks - Error: Failed to load Formbricks SDK" ,
241+ "🧱 Formbricks - Error: Failed to load Formbricks SDK"
211242 ) ;
212243
213244 // Restore setTimeout
@@ -222,13 +253,13 @@ describe("load-formbricks", () => {
222253 } ;
223254
224255 vi . spyOn ( document . head , "appendChild" ) . mockImplementation (
225- createErrorScriptMock ( ) ,
256+ createErrorScriptMock ( )
226257 ) ;
227258
228259 await loadFormbricksToProxy ( "setup" , setupArgs ) ;
229260
230261 expect ( consoleSpy ) . toHaveBeenCalledWith (
231- "🧱 Formbricks - Error: Failed to load Formbricks SDK" ,
262+ "🧱 Formbricks - Error: Failed to load Formbricks SDK"
232263 ) ;
233264 } ) ;
234265
@@ -240,14 +271,14 @@ describe("load-formbricks", () => {
240271 } ;
241272
242273 vi . spyOn ( document . head , "appendChild" ) . mockImplementation (
243- createSetupFailureMock ( ) ,
274+ createSetupFailureMock ( )
244275 ) ;
245276
246277 await loadFormbricksToProxy ( "setup" , setupArgs ) ;
247278
248279 expect ( consoleSpy ) . toHaveBeenCalledWith (
249280 "🧱 Formbricks - Error: setup failed" ,
250- expect . any ( Error ) ,
281+ expect . any ( Error )
251282 ) ;
252283 } ) ;
253284 } ) ;
@@ -259,7 +290,7 @@ describe("load-formbricks", () => {
259290 await loadFormbricksToProxy ( "track" , "test-event" ) ;
260291
261292 expect ( consoleSpy ) . toHaveBeenCalledWith (
262- "🧱 Formbricks - Warning: Formbricks not initialized. This method will be queued and executed after initialization." ,
293+ "🧱 Formbricks - Warning: Formbricks not initialized. This method will be queued and executed after initialization."
263294 ) ;
264295 } ) ;
265296
@@ -268,7 +299,7 @@ describe("load-formbricks", () => {
268299 await loadFormbricksToProxy ( "track" , "queued-event" ) ;
269300 expect ( warnSpy ) . toHaveBeenCalled ( ) ;
270301 vi . spyOn ( document . head , "appendChild" ) . mockImplementation (
271- createSuccessfulScriptMock ( ) ,
302+ createSuccessfulScriptMock ( )
272303 ) ;
273304 await loadFormbricksToProxy ( "setup" , {
274305 appUrl : "https://app.formbricks.com" ,
@@ -286,7 +317,7 @@ describe("load-formbricks", () => {
286317 } ;
287318
288319 vi . spyOn ( document . head , "appendChild" ) . mockImplementation (
289- createSuccessfulScriptMock ( ) ,
320+ createSuccessfulScriptMock ( )
290321 ) ;
291322
292323 // First, set up the SDK
0 commit comments