소스 검색

#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,11 +8,12 @@ export default {
8 8
     return a !== null && a !== void 0
9 9
   },
10 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 18
   hasValue : (a, b) => (a !== void 0) && (Array.isArray(a) ? a.length !==0 : true),
18 19
   isArray : (a, b) => Array.isArray(a),

+ 29
- 3
test/test-0.6.0.js 파일 보기

@@ -32,7 +32,7 @@ describe('writeFile and readFile test', (report, done) => {
32 32
     .then(() => fs.readFile(path, 'utf8'))
33 33
     .then((actual) => {
34 34
       report(<Assert key="utf8 content should correct" expect={data} actual={actual}/>)
35
-      data += 'base64'
35
+      data = 'base64'
36 36
       return fs.writeFile(path, RNFetchBlob.base64.encode('base64'), 'base64')
37 37
     })
38 38
     .then(() => fs.readFile(path, 'base64'))
@@ -40,7 +40,7 @@ describe('writeFile and readFile test', (report, done) => {
40 40
       report(<Assert key="base64 content should correct"
41 41
         expect={RNFetchBlob.base64.decode(RNFetchBlob.base64.encode(data))}
42 42
         actual={RNFetchBlob.base64.decode(actual)}/>)
43
-      data += 'ascii'
43
+      data = 'ascii'
44 44
       return fs.writeFile(path, getASCIIArray('ascii'), 'ascii');
45 45
     })
46 46
     .then(() => fs.readFile(path, 'ascii'))
@@ -54,8 +54,34 @@ describe('writeFile and readFile test', (report, done) => {
54 54
 })
55 55
 
56 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 87
 function getASCIIArray(str) {