Ben Hsieh 8 anni fa
parent
commit
363d59a657
2 ha cambiato i file con 70 aggiunte e 0 eliminazioni
  1. 16
    0
      test-server/public/json-dummy.json
  2. 54
    0
      test/test-0.9.5.js

+ 16
- 0
test-server/public/json-dummy.json Vedi File

@@ -0,0 +1,16 @@
1
+{
2
+  "name": "fetchblob-dev",
3
+  "version": "0.9.4",
4
+  "private": true,
5
+  "scripts": {
6
+    "start": "node node_modules/react-native/local-cli/cli.js start",
7
+    "test": "sh test.sh"
8
+  },
9
+  "devDependencies": {
10
+    "body-parser": "^1.15.0",
11
+    "chalk": "^1.1.3",
12
+    "chokidar": "^1.5.1",
13
+    "express": "^4.13.4",
14
+    "multer": "^1.1.0"
15
+  }
16
+}

+ 54
- 0
test/test-0.9.5.js Vedi File

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