@@ -7,6 +7,9 @@ afterEach(() => {
77 mock . restoreAll ( )
88} )
99
10+ // https://github.com/modosc/global-jsdom/issues/440
11+ globalThis = globalThis . window
12+
1013describe ( "getKeyFromResponse" , ( ) => {
1114 test ( "returns key" , ( ) => {
1215 const responseText = `<?xml version="1.0" encoding="UTF-8"?>
@@ -98,7 +101,7 @@ describe("S3FileInput", () => {
98101 const submitButton = document . createElement ( "button" )
99102 form . appendChild ( submitButton )
100103 submitButton . setAttribute ( "type" , "submit" )
101- const event = new globalThis . SubmitEvent ( "submit" , { submitter : submitButton } )
104+ const event = new SubmitEvent ( "submit" , { submitter : submitButton } )
102105 const input = new s3file . S3FileInput ( )
103106 form . appendChild ( input )
104107 await input . submitHandler ( event )
@@ -112,18 +115,17 @@ describe("S3FileInput", () => {
112115 const input = new s3file . S3FileInput ( )
113116 form . appendChild ( input )
114117 Object . defineProperty ( input , "files" , {
115- get : ( ) => [ new globalThis . File ( [ "" ] , "file.txt" ) ] ,
118+ get : ( ) => [ new File ( [ "" ] , "file.txt" ) ] ,
116119 } )
117120 assert ( ! input . upload )
118121 assert . strictEqual ( input . files . length , 1 )
119122 input . uploadHandler ( )
120- console . info ( input . upload )
121123 assert ( input . upload )
122124 assert ( form . pendingRequests )
123125 } )
124126
125127 test ( "fromDataHandler" , ( ) => {
126- const event = new globalThis . CustomEvent ( "formdata" , { formData : new FormData ( ) } )
128+ const event = new CustomEvent ( "formdata" , { formData : new FormData ( ) } )
127129 const form = document . createElement ( "form" )
128130 document . body . appendChild ( form )
129131 const input = new s3file . S3FileInput ( )
@@ -143,7 +145,7 @@ describe("S3FileInput", () => {
143145 input . setAttribute ( "data-fields-policy" , "policy" )
144146 form . appendChild ( input )
145147 Object . defineProperty ( input , "files" , {
146- get : ( ) => [ new globalThis . File ( [ "" ] , "file.txt" ) ] ,
148+ get : ( ) => [ new File ( [ "" ] , "file.txt" ) ] ,
147149 } )
148150 const responseText = `<?xml version="1.0" encoding="UTF-8"?>
149151 <PostResponse>
@@ -153,10 +155,10 @@ describe("S3FileInput", () => {
153155 <ETag>"a38155039ec348f97dfd63da4cb2619d"</ETag>
154156 </PostResponse>`
155157 const response = { status : 201 , text : async ( ) => responseText }
156- globalThis . fetch = mock . fn ( async ( ) => response )
158+ fetch = mock . fn ( async ( ) => response )
157159 assert ( input . files . length === 1 )
158160 await input . uploadFiles ( )
159- assert ( globalThis . fetch . mock . calls . length === 1 )
161+ assert ( fetch . mock . calls . length === 1 )
160162 assert . deepStrictEqual ( input . keys , [ "tmp/s2file/some file.jpeg" ] )
161163 } )
162164
@@ -166,13 +168,13 @@ describe("S3FileInput", () => {
166168 const input = new s3file . S3FileInput ( )
167169 form . appendChild ( input )
168170 Object . defineProperty ( input , "files" , {
169- get : ( ) => [ new globalThis . File ( [ "" ] , "file.txt" ) ] ,
171+ get : ( ) => [ new File ( [ "" ] , "file.txt" ) ] ,
170172 } )
171173 const response = { status : 400 , statusText : "Bad Request" }
172- globalThis . fetch = mock . fn ( async ( ) => response )
174+ fetch = mock . fn ( async ( ) => response )
173175 assert ( input . files . length === 1 )
174176 await input . uploadFiles ( )
175- assert ( globalThis . fetch . mock . calls . length === 1 )
177+ assert ( fetch . mock . calls . length === 1 )
176178 assert . deepStrictEqual ( input . keys , [ ] )
177179 assert . strictEqual ( input . validationMessage , "Bad Request" )
178180 } )
@@ -183,14 +185,14 @@ describe("S3FileInput", () => {
183185 const input = new s3file . S3FileInput ( )
184186 form . appendChild ( input )
185187 Object . defineProperty ( input , "files" , {
186- get : ( ) => [ new globalThis . File ( [ "" ] , "file.txt" ) ] ,
188+ get : ( ) => [ new File ( [ "" ] , "file.txt" ) ] ,
187189 } )
188- globalThis . fetch = mock . fn ( async ( ) => {
190+ fetch = mock . fn ( async ( ) => {
189191 throw new Error ( "Network Error" )
190192 } )
191193 assert ( input . files . length === 1 )
192194 await input . uploadFiles ( )
193- assert ( globalThis . fetch . mock . calls . length === 1 )
195+ assert ( fetch . mock . calls . length === 1 )
194196 assert . deepStrictEqual ( input . keys , [ ] )
195197 assert . strictEqual ( input . validationMessage , "Error: Network Error" )
196198 } )
0 commit comments