Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit d73452f

Browse files
committed
#27 test cases
1 parent 37f4632 commit d73452f

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

test/react-native-testkit/lib/comparer.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ export default {
88
return a !== null && a !== void 0
99
},
1010
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;
1617
},
1718
hasValue : (a, b) => (a !== void 0) && (Array.isArray(a) ? a.length !==0 : true),
1819
isArray : (a, b) => Array.isArray(a),

test/test-0.6.0.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ describe('writeFile and readFile test', (report, done) => {
3232
.then(() => fs.readFile(path, 'utf8'))
3333
.then((actual) => {
3434
report(<Assert key="utf8 content should correct" expect={data} actual={actual}/>)
35-
data += 'base64'
35+
data = 'base64'
3636
return fs.writeFile(path, RNFetchBlob.base64.encode('base64'), 'base64')
3737
})
3838
.then(() => fs.readFile(path, 'base64'))
3939
.then((actual) => {
4040
report(<Assert key="base64 content should correct"
4141
expect={RNFetchBlob.base64.decode(RNFetchBlob.base64.encode(data))}
4242
actual={RNFetchBlob.base64.decode(actual)}/>)
43-
data += 'ascii'
43+
data = 'ascii'
4444
return fs.writeFile(path, getASCIIArray('ascii'), 'ascii');
4545
})
4646
.then(() => fs.readFile(path, 'ascii'))
@@ -54,8 +54,34 @@ describe('writeFile and readFile test', (report, done) => {
5454
})
5555

5656
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+
})
5784

58-
// TODO
5985
})
6086

6187
function getASCIIArray(str) {

0 commit comments

Comments
 (0)