No Description

test-0.10.3.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import RNTest from './react-native-testkit/'
  2. import React from 'react'
  3. import _ from 'lodash'
  4. import RNFetchBlob from 'react-native-fetch-blob'
  5. import {
  6. StyleSheet,
  7. Text,
  8. View,
  9. ScrollView,
  10. Linking,
  11. Platform,
  12. Dimensions,
  13. BackAndroid,
  14. AsyncStorage,
  15. Image,
  16. } from 'react-native';
  17. window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
  18. window.Blob = RNFetchBlob.polyfill.Blob
  19. const JSONStream = RNFetchBlob.JSONStream
  20. const fs = RNFetchBlob.fs
  21. const { Assert, Comparer, Info, prop } = RNTest
  22. const describe = RNTest.config({
  23. group : '0.10.3',
  24. run : true,
  25. expand : true,
  26. timeout : 20000,
  27. })
  28. const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
  29. const dirs = RNFetchBlob.fs.dirs
  30. let prefix = ((Platform.OS === 'android') ? 'file://' : '')
  31. let begin = Date.now()
  32. describe('#230 #249 cookies manipulation', (report, done) => {
  33. RNFetchBlob
  34. .fetch('GET', `${TEST_SERVER_URL}/cookie/249230`)
  35. .then((res) => RNFetchBlob.net.getCookies())
  36. .then((cookies) => {
  37. console.log(cookies)
  38. report(<Assert
  39. key="should set 10 cookies"
  40. expect={10}
  41. actual={cookies['localhost'].length}/>)
  42. return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/cookie-echo`)
  43. })
  44. .then((res) => {
  45. console.log(res.data)
  46. let cookies = String(res.data).split(';')
  47. report(<Assert
  48. key="should send 10 cookies"
  49. expect={10}
  50. actual={cookies.length}/>)
  51. return RNFetchBlob.net.removeCookies()
  52. })
  53. .then(() => RNFetchBlob.net.getCookies('localhost'))
  54. .then((cookies) => {
  55. report(<Assert
  56. key="should have no cookies"
  57. expect={undefined}
  58. actual={cookies['localhost']}/>)
  59. return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/cookie-echo`)
  60. })
  61. .then((res) => {
  62. console.log(res.data)
  63. let cookies = String(res.data).split(';')
  64. cookies = _.reject(cookies, r => r.length < 2)
  65. report(<Assert
  66. key="should send no cookies"
  67. expect={0}
  68. actual={cookies.length}/>)
  69. done()
  70. })
  71. })