This repository has been archived by the owner on Mar 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
107 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import RNTest from './react-native-testkit/' | ||
import React from 'react' | ||
import RNFetchBlob from 'react-native-fetch-blob' | ||
|
||
import { | ||
StyleSheet, | ||
Text, | ||
View, | ||
ScrollView, | ||
Platform, | ||
Dimensions, | ||
Image, | ||
} from 'react-native'; | ||
|
||
const fs = RNFetchBlob.fs | ||
const { Assert, Comparer, Info, prop } = RNTest | ||
const describe = RNTest.config({ | ||
group : '0.5.3', | ||
run : true, | ||
expand : false, | ||
}) | ||
const { TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop() | ||
|
||
let prefix = ((Platform.OS === 'android') ? 'file://' : '') | ||
|
||
|
||
describe('GET request with params', (report, done) => { | ||
let time = Date.now() | ||
RNFetchBlob | ||
.config({ fileCache : true, trusty : true }) | ||
.fetch('GET', `${TEST_SERVER_URL_SSL}/params?time=${time}&name=RNFetchBlobParams&lang=中文`) | ||
.then((resp) => { | ||
let file = resp.path() | ||
return RNFetchBlob.fs.readStream(resp.path(), 'utf8') | ||
}) | ||
.then((stream) => { | ||
let result = '' | ||
stream.open() | ||
stream.onData((chunk) => { | ||
result += chunk | ||
}) | ||
stream.onEnd(() => { | ||
result = JSON.parse(result) | ||
report(<Assert key="param#1 should correct" | ||
expect={parseInt(time)} | ||
actual={parseInt(result.time)}/>, | ||
<Assert key="param#2 should correct" | ||
expect={'RNFetchBlobParams'} | ||
actual={result.name}/>, | ||
<Assert key="param contains unicode data should correct" | ||
expect={'中文'} | ||
actual={result.lang}/>) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
|
||
describe('POST request with params', (report, done) => { | ||
let time = Date.now() | ||
RNFetchBlob.config({ fileCache : true, trusty : true }) | ||
.fetch('POST', `${TEST_SERVER_URL_SSL}/params?time=${time}&name=RNFetchBlobParams&lang=中文`) | ||
.then((resp) => { | ||
let file = resp.path() | ||
return RNFetchBlob.fs.readStream(resp.path(), 'utf8') | ||
}) | ||
.then((stream) => { | ||
let result = '' | ||
stream.open() | ||
stream.onData((chunk) => { | ||
result += chunk | ||
}) | ||
stream.onEnd(() => { | ||
result = JSON.parse(result) | ||
report(<Assert key="param#1 should correct" | ||
expect={parseInt(time)} | ||
actual={parseInt(result.time)}/>, | ||
<Assert key="param#2 should correct" | ||
expect={'RNFetchBlobParams'} | ||
actual={result.name}/>, | ||
<Assert key="param contains unicode data should correct" | ||
expect={'中文'} | ||
actual={result.lang}/>) | ||
done() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters