Ben Hsieh před 8 roky
rodič
revize
dd1cb504be
3 změnil soubory, kde provedl 29 přidání a 3 odebrání
  1. 28
    1
      test/test-blob.js
  2. 0
    1
      test/test-firebase.js
  3. 1
    1
      test/test-init.js

+ 28
- 1
test/test-blob.js Zobrazit soubor

@@ -16,6 +16,7 @@ import {
16 16
 
17 17
 const fs = RNFetchBlob.fs
18 18
 const Blob = RNFetchBlob.polyfill.Blob
19
+const File = RNFetchBlob.polyfill.File
19 20
 
20 21
 const { Assert, Comparer, Info, prop } = RNTest
21 22
 const describe = RNTest.config({
@@ -99,7 +100,7 @@ describe('create Blob without any agument', (report, done) => {
99 100
 })
100 101
 
101 102
 describe('blob clear cache test', (report, done) => {
102
-  let expect = 'test-'+Date.now()
103
+  let expect = 'test-' + Date.now()
103 104
   Blob.clearCache()
104 105
       .then(() => Blob.build(expect))
105 106
       .then((b) => fs.readFile(b.getRNFetchBlobRef(), 'utf8'))
@@ -119,3 +120,29 @@ describe('blob clear cache test', (report, done) => {
119 120
         done()
120 121
       })
121 122
 })
123
+
124
+describe('create blob using FormData', (report, done) => {
125
+  let form = new FormData()
126
+  let fname = 'blob-test' + Date.now()
127
+  File.build(RNTest.prop('image'), { type:'image/png;base64' })
128
+      .then((f) => {
129
+        f.name = 'test.png'
130
+        form.append('name', fname)
131
+        form.append('blob', f)
132
+        return Blob.build(form)
133
+      })
134
+      .then((b) => RNFetchBlob
135
+                    .fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
136
+                      'content-type' : 'multipart/form-data; boundary='+b.multipartBoundary
137
+                    }, RNFetchBlob.wrap(b.getRNFetchBlobRef())))
138
+      .then((resp) => {
139
+        report(
140
+          <Assert key="form data verification #1"
141
+            actual={resp.json().files[0].originalname}
142
+            expect={'test.png'}/>,
143
+          <Assert key="form data verification #2"
144
+            actual={resp.json().fields.name}
145
+            expect={fname}/>)
146
+        done()
147
+      })
148
+})

+ 0
- 1
test/test-firebase.js Zobrazit soubor

@@ -20,7 +20,6 @@ const Blob = RNFetchBlob.polyfill.Blob
20 20
 
21 21
 window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
22 22
 window.Blob = Blob
23
-window.FormData = RNFetchBlob.polyfill.FormData
24 23
 
25 24
 const { Assert, Comparer, Info, prop } = RNTest
26 25
 const describe = RNTest.config({

+ 1
- 1
test/test-init.js Zobrazit soubor

@@ -69,5 +69,5 @@ describe('GET image from server', (report, done) => {
69 69
 // require('./test-fs')
70 70
 // require('./test-xmlhttp')
71 71
 require('./test-blob')
72
-// require('./test-firebase')
72
+require('./test-firebase')
73 73
 // require('./test-android')