暫無描述

test-0.8.2.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 = Blob
  15. window.fetch = new RNFetchBlob.polyfill.Fetch({
  16. auto : true,
  17. binaryContentTypes : ['image/', 'video/', 'audio/']
  18. }).provider.fetch
  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('unicode file access', (report, done) => {
  31. let path = dirs.DocumentDir + '/chinese.tmp'
  32. fs.writeFile(path, '你好!', 'utf8')
  33. .then(() => fs.readFile(path, 'utf8'))
  34. .then((data) => {
  35. console.log(data)
  36. done()
  37. })
  38. })
  39. describe('whatwg-fetch - GET should work correctly', (report, done) => {
  40. console.log(fetch)
  41. fetch(`${TEST_SERVER_URL}/unicode`, {
  42. method : 'GET'
  43. })
  44. .then((res) => {
  45. console.log('fetch resp',res)
  46. return res.text()
  47. })
  48. .then((blob) => {
  49. console.log(blob)
  50. done()
  51. })
  52. })