瀏覽代碼

#27 test cases

Ben Hsieh 8 年之前
父節點
當前提交
d73452f786
共有 2 個文件被更改,包括 35 次插入8 次删除
  1. 6
    5
      test/react-native-testkit/lib/comparer.js
  2. 29
    3
      test/test-0.6.0.js

+ 6
- 5
test/react-native-testkit/lib/comparer.js 查看文件

8
     return a !== null && a !== void 0
8
     return a !== null && a !== void 0
9
   },
9
   },
10
   equalToArray : (a, b) => {
10
   equalToArray : (a, b) => {
11
-    if(!Array.isArray(a) && Array.isArray(b))
12
-      return false
13
-    return (a.length == b.length) && a.every(function(element, index) {
14
-      return element === b[index];
15
-    });
11
+    var i = a.length;
12
+    if (i != b.length) return false;
13
+    while (i--) {
14
+        if (a[i] !== b[i]) return false;
15
+    }
16
+    return true;
16
   },
17
   },
17
   hasValue : (a, b) => (a !== void 0) && (Array.isArray(a) ? a.length !==0 : true),
18
   hasValue : (a, b) => (a !== void 0) && (Array.isArray(a) ? a.length !==0 : true),
18
   isArray : (a, b) => Array.isArray(a),
19
   isArray : (a, b) => Array.isArray(a),

+ 29
- 3
test/test-0.6.0.js 查看文件

32
     .then(() => fs.readFile(path, 'utf8'))
32
     .then(() => fs.readFile(path, 'utf8'))
33
     .then((actual) => {
33
     .then((actual) => {
34
       report(<Assert key="utf8 content should correct" expect={data} actual={actual}/>)
34
       report(<Assert key="utf8 content should correct" expect={data} actual={actual}/>)
35
-      data += 'base64'
35
+      data = 'base64'
36
       return fs.writeFile(path, RNFetchBlob.base64.encode('base64'), 'base64')
36
       return fs.writeFile(path, RNFetchBlob.base64.encode('base64'), 'base64')
37
     })
37
     })
38
     .then(() => fs.readFile(path, 'base64'))
38
     .then(() => fs.readFile(path, 'base64'))
40
       report(<Assert key="base64 content should correct"
40
       report(<Assert key="base64 content should correct"
41
         expect={RNFetchBlob.base64.decode(RNFetchBlob.base64.encode(data))}
41
         expect={RNFetchBlob.base64.decode(RNFetchBlob.base64.encode(data))}
42
         actual={RNFetchBlob.base64.decode(actual)}/>)
42
         actual={RNFetchBlob.base64.decode(actual)}/>)
43
-      data += 'ascii'
43
+      data = 'ascii'
44
       return fs.writeFile(path, getASCIIArray('ascii'), 'ascii');
44
       return fs.writeFile(path, getASCIIArray('ascii'), 'ascii');
45
     })
45
     })
46
     .then(() => fs.readFile(path, 'ascii'))
46
     .then(() => fs.readFile(path, 'ascii'))
54
 })
54
 })
55
 
55
 
56
 describe('append file test', (report, done) => {
56
 describe('append file test', (report, done) => {
57
+  let path = dirs.DocumentDir + '/append-test'+Date.now()
58
+  let content = 'test on ' + Date.now()
59
+  fs.writeFile(path, content, 'utf8')
60
+    .then(() => fs.appendFile(path, '100', 'utf8', true))
61
+    .then(() => fs.readFile(path, 'utf8'))
62
+    .then((data) => {
63
+      report(
64
+        <Assert key="utf8 data should be appended"
65
+          expect={content + '100'}
66
+          actual={data} />)
67
+      return fs.appendFile(path, getASCIIArray('200'), 'ascii')
68
+    })
69
+    .then(() => fs.readFile(path, 'ascii'))
70
+    .then((data) => {
71
+      report(<Assert key="ascii data should be appended"
72
+        expect={getASCIIArray(content + '100' + '200')}
73
+        comparer={Comparer.equalToArray}
74
+        actual={data} />)
75
+      return fs.appendFile(path, RNFetchBlob.base64.encode('300'), 'base64')
76
+    })
77
+    .then(() => fs.readFile(path, 'base64'))
78
+    .then((data) => {
79
+      report(<Assert key="base64 data should be appended"
80
+        expect={content + '100' + '200' + '300'}
81
+        actual={RNFetchBlob.base64.decode(data)} />)
82
+        done()
83
+    })
57
 
84
 
58
-  // TODO 
59
 })
85
 })
60
 
86
 
61
 function getASCIIArray(str) {
87
 function getASCIIArray(str) {