|
@@ -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
|
+})
|