xhrhelpers

xhr testing helper

Usage no npm install needed!

<script type="module">
  import xhrhelpers from 'https://cdn.skypack.dev/xhrhelpers';
</script>

README

xhrhelpers

Build Status

xhrhelpers contains function to help interacting with XHR objects through promises.

Usage

  • Use the XHR status
promisifiedXHR
    .then(xhrHelpers.status)
    .then(console.log); // Logs the status of the xhr
  • Use the XHR response object
promisifiedXHR
    .then(xhrHelpers.responseObject)
    .then(console.log); // Logs the response object of the xhr
  • Use the XHR response text
promisifiedXHR
    .then(xhrHelpers.responseText)
    .then(console.log); // Logs the response text of the xhr
  • Check if the status code was successful (under 299)
promisifiedXHR
    .then(xhrHelpers.twoHundredsOrThrow)
    .then(console.log); // Throws an error if the status code was > 299

Install it

$ npm install xhrhelpers

Test it

$ npm test