|
@@ -0,0 +1,54 @@
|
|
1
|
+import RNTest from './react-native-testkit/'
|
|
2
|
+import React from 'react'
|
|
3
|
+import RNFetchBlob from 'react-native-fetch-blob'
|
|
4
|
+import {
|
|
5
|
+ StyleSheet,
|
|
6
|
+ Text,
|
|
7
|
+ View,
|
|
8
|
+ ScrollView,
|
|
9
|
+ Platform,
|
|
10
|
+ Dimensions,
|
|
11
|
+ Image,
|
|
12
|
+ TouchableOpacity,
|
|
13
|
+} from 'react-native';
|
|
14
|
+
|
|
15
|
+window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
|
|
16
|
+window.Blob = RNFetchBlob.polyfill.Blob
|
|
17
|
+
|
|
18
|
+const fs = RNFetchBlob.fs
|
|
19
|
+const { Assert, Comparer, Info, prop } = RNTest
|
|
20
|
+const describe = RNTest.config({
|
|
21
|
+ group : '0.9.5',
|
|
22
|
+ run : true,
|
|
23
|
+ expand : false,
|
|
24
|
+ timeout : 20000,
|
|
25
|
+})
|
|
26
|
+const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
|
|
27
|
+const dirs = RNFetchBlob.fs.dirs
|
|
28
|
+
|
|
29
|
+let prefix = ((Platform.OS === 'android') ? 'file://' : '')
|
|
30
|
+
|
|
31
|
+describe('issue #122 force response data format', (report, done) => {
|
|
32
|
+
|
|
33
|
+ RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/json-dummy.json`, {
|
|
34
|
+ 'RNFB-Response' : 'base64'
|
|
35
|
+ })
|
|
36
|
+ .then((res) => {
|
|
37
|
+ let r = RNFetchBlob.base64.decode(res.data)
|
|
38
|
+ report(
|
|
39
|
+ <Assert key="test data verify" expect="fetchblob-dev" actual={JSON.parse(r).name}/>,
|
|
40
|
+ <Assert key="should successfully decode the data" expect={true} actual={true}/>)
|
|
41
|
+ return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/json-dummy.json`)
|
|
42
|
+ })
|
|
43
|
+ .then((res) => {
|
|
44
|
+ report(
|
|
45
|
+ <Assert key="response should in format of plain-text" expect="fetchblob-dev" actual={JSON.parse(res.data).name}/>)
|
|
46
|
+ done()
|
|
47
|
+ })
|
|
48
|
+ .catch(() => {
|
|
49
|
+ report(
|
|
50
|
+ <Assert key="Should successfully decode the data" expect={true} actual={false}/>)
|
|
51
|
+ done()
|
|
52
|
+ })
|
|
53
|
+
|
|
54
|
+})
|