Keine Beschreibung

test-0.5.3.js 2.4KB

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