Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grabbing server response in promise chain #20

Open
msiebuhr opened this issue Jan 24, 2018 · 1 comment
Open

Grabbing server response in promise chain #20

msiebuhr opened this issue Jan 24, 2018 · 1 comment

Comments

@msiebuhr
Copy link

I have a need for extracting the response body (for grabbing returned state), but this feel quite wrong to do:

expect(foo, 'to yield exchange', {...})
  .then(function (exchange) {
    var body = JSON.parse(exchange.httpExchange.response._rawBody.toString('utf-8'));
    ...
   })

There wouldn't be a better way of doing this somewhere?

@papandreou
Copy link
Member

Hey Morten, long time no see! Are you dropping by Copenhagen.js tomorrow?

Hmm, if it's an application/json response body, then httpExchange.response.body is supposed to contain the deserialized JSON:

const { httpExchange: { response: { body } } } =
  await expect(app, 'to yield exchange satisfying', { ... });

The httpExchange object is a messy.HttpExchange instance, but it's not terribly well documented, hah: https://github.com/papandreou/messy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants