瀏覽代碼

Add test case for #26 implementations

Ben Hsieh 8 年之前
父節點
當前提交
0f9c03b157
共有 2 個檔案被更改,包括 91 行新增23 行删除
  1. 86
    0
      test/test-0.5.2.js
  2. 5
    23
      test/test-init.js

+ 86
- 0
test/test-0.5.2.js 查看文件

@@ -0,0 +1,86 @@
1
+import RNTest from './react-native-testkit/'
2
+import React from 'react'
3
+import RNFetchBlob from 'react-native-fetch-blob'
4
+
5
+import {
6
+  StyleSheet,
7
+  Text,
8
+  View,
9
+  ScrollView,
10
+  Platform,
11
+  Dimensions,
12
+  Image,
13
+} from 'react-native';
14
+
15
+const fs = RNFetchBlob.fs
16
+const { Assert, Comparer, Info, prop } = RNTest
17
+const describe = RNTest.config({
18
+  group : '0.5.2',
19
+  run : true,
20
+  expand : false,
21
+})
22
+const { TEST_SERVER_URL, FILENAME, DROPBOX_TOKEN, styles } = prop()
23
+
24
+let prefix = ((Platform.OS === 'android') ? 'file://' : '')
25
+
26
+
27
+describe('GET request with params', (report, done) => {
28
+  let time = Date.now()
29
+  RNFetchBlob.config({ fileCache : true })
30
+    .fetch('GET', `${TEST_SERVER_URL}/params?time=${time}&name=RNFetchBlobParams&lang=中文`)
31
+    .then((resp) => {
32
+      let file = resp.path()
33
+      return RNFetchBlob.fs.readStream(resp.path(), 'utf8')
34
+    })
35
+    .then((stream) => {
36
+      let result = ''
37
+      stream.open()
38
+      stream.onData((chunk) => {
39
+        result += chunk
40
+      })
41
+      stream.onEnd(() => {
42
+        result = JSON.parse(result)
43
+        report(<Assert key="param#1 should correct"
44
+          expect={parseInt(time)}
45
+          actual={parseInt(result.time)}/>,
46
+        <Assert key="param#2 should correct"
47
+          expect={'RNFetchBlobParams'}
48
+          actual={result.name}/>,
49
+        <Assert key="param contains unicode data should correct"
50
+          expect={'中文'}
51
+          actual={result.lang}/>)
52
+          done()
53
+      })
54
+    })
55
+})
56
+
57
+
58
+describe('POST request with params', (report, done) => {
59
+  let time = Date.now()
60
+  RNFetchBlob.config({ fileCache : true })
61
+    .fetch('POST', `${TEST_SERVER_URL}/params?time=${time}&name=RNFetchBlobParams&lang=中文`)
62
+    .then((resp) => {
63
+      let file = resp.path()
64
+      return RNFetchBlob.fs.readStream(resp.path(), 'utf8')
65
+    })
66
+    .then((stream) => {
67
+      let result = ''
68
+      stream.open()
69
+      stream.onData((chunk) => {
70
+        result += chunk
71
+      })
72
+      stream.onEnd(() => {
73
+        result = JSON.parse(result)
74
+        report(<Assert key="param#1 should correct"
75
+          expect={parseInt(time)}
76
+          actual={parseInt(result.time)}/>,
77
+        <Assert key="param#2 should correct"
78
+          expect={'RNFetchBlobParams'}
79
+          actual={result.name}/>,
80
+        <Assert key="param contains unicode data should correct"
81
+          expect={'中文'}
82
+          actual={result.lang}/>)
83
+          done()
84
+      })
85
+    })
86
+})

+ 5
- 23
test/test-init.js 查看文件

@@ -50,26 +50,8 @@ describe('GET image from server', (report, done) => {
50 50
     })
51 51
 })
52 52
 
53
-// // Only use when doing memory leaking test 
54
-// RNTest.config({
55
-//   timeout : 900000000
56
-// })('Memory leaking test', (report, done) => {
57
-//   let promises = []
58
-//   for(let i = 0 ; i < 2000; i++) {
59
-//     promises.push(RNFetchBlob
60
-//       .fetch('GET', `${TEST_SERVER_URL}/public/github.png`, {
61
-//         Authorization : 'Bearer abde123eqweje'
62
-//       })
63
-//     )
64
-//   }
65
-//   Promise.all(promises).then(() => {
66
-//     report(<Assert key="test finished" expect={true} actual={true}/>)
67
-//     done()
68
-//   })
69
-// })
70
-
71
-
72
-require('./test-0.1.x-0.4.x')
73
-require('./test-0.5.x')
74
-require('./test-fs')
75
-require('./test-android')
53
+// require('./test-0.1.x-0.4.x')
54
+// require('./test-0.5.1')
55
+require('./test-0.5.2')
56
+// require('./test-fs')
57
+// require('./test-android')