jameslnewell / xhr-mock

Utility for mocking XMLHttpRequest.
196 stars 48 forks source link

This feature hasn't been implmented yet. Please submit an Issue or Pull Request on Github. #13

Closed chrisabrams closed 7 years ago

chrisabrams commented 8 years ago

This error is very vague; I have no idea what feature is not implemented. :O

For reference, here is what I tried doing:

var xhrMock = require('xhr-mock')

xhrMock.setup()

xhrMock.post('http://localhost:4567/foo', function(req, res) {
  return res
    .status(201)
    .header('Content-Type', 'application/json')
    .body(JSON.stringify({
      created: true
    }))
})

var send = return new Promise( (resolve, reject) => {

  var request = new XMLHttpRequest()

  request.open('POST', 'http://localhost:4567/foo', true)

  request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded')

  request.addEventListener('load', function onLoad(res) {
    console.log('res', res)
    resolve(JSON.parse(res.responseText))
  })

  request.addEventListener('error', function onXMLHttpRequestError(e) {
    reject(e)
  })

  request.send(pkg)

})

send()
chrisabrams commented 8 years ago

It would appear that addEventListener is not supported: https://github.com/jameslnewell/xhr-mock/blob/26a385c580c109bfbcb2acabf830f44b6a83b5cd/lib/MockXMLHttpRequest.js#L215

jameslnewell commented 8 years ago

Thanks for reporting!

I haven't used (a library that uses) addEventListener yet and haven't found the time/need to implement it yet. Would you be able to submit a PR that improves the error messaging, or that implements the feature according to spec?

jameslnewell commented 7 years ago

This was recently implemented in a PR.