Brak opisu

test-0.8.2.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
  14. window.Blob = RNFetchBlob.polyfill.Blob
  15. window.fetch = new RNFetchBlob.polyfill.Fetch({
  16. auto : true,
  17. binaryContentTypes : ['image/', 'video/', 'audio/']
  18. }).build()
  19. const fs = RNFetchBlob.fs
  20. const { Assert, Comparer, Info, prop } = RNTest
  21. const describe = RNTest.config({
  22. group : '0.8.2',
  23. run : true,
  24. expand : true,
  25. timeout : 20000,
  26. })
  27. const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
  28. const dirs = RNFetchBlob.fs.dirs
  29. let prefix = ((Platform.OS === 'android') ? 'file://' : '')
  30. describe('whatwg-fetch - GET should work correctly', (report, done) => {
  31. console.log(fetch)
  32. fetch(`${TEST_SERVER_URL}/unicode`, {
  33. method : 'GET'
  34. })
  35. .then((res) => {
  36. return res.json()
  37. })
  38. .then((data) => {
  39. console.log(data)
  40. report(<Assert key="data should correct" expect={'你好!'} actual={data.data}/>)
  41. done()
  42. })
  43. })
  44. RNTest.config({
  45. group : '0.8.2',
  46. run : true,
  47. expand : false,
  48. timeout : 24000
  49. })('request should not retry after timed out', (report, done) => {
  50. let count = 0
  51. RNFetchBlob
  52. .config({ timeout : 3000 })
  53. .fetch('GET', `${TEST_SERVER_URL}/timeout`)
  54. .then((res) => {
  55. report(<Assert key="request should not success" expect={true} actual={false}/>)
  56. })
  57. .catch(() => {
  58. count ++
  59. })
  60. setTimeout(() => {
  61. report(<Assert key="request does not retry" expect={1} actual={count}/>)
  62. done()
  63. }, 12000)
  64. })