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

Support res.format #94

Closed
jmnsf opened this issue Mar 31, 2016 · 6 comments
Closed

Support res.format #94

jmnsf opened this issue Mar 31, 2016 · 6 comments

Comments

@jmnsf
Copy link
Contributor

jmnsf commented Mar 31, 2016

res.format is super useful for having an endpoint that handles multiple Accept headers. Without this, these endpoints can't be tested.

@Vishal-Joshi
Copy link

Same issue! When can we expect a resolution for it? I am stuck because of it and my controller cant be tested without its support?

Did you find another alternative @jmnsf meanwhile fix arrives?

@jmnsf
Copy link
Contributor Author

jmnsf commented Apr 1, 2016

@Vishal-Joshi I've mocked the behaviour, temporarily. Not a very elegant solution since it is heavily coupled to the formats Object provided, but works for the time being.

context('given an HTML request', () => {
  beforeEach(() => httpMocks.createResponse().format = formats => formats.html());

Doing it in httpMocks requires a reference to the Request headers from the mockResponse that isn't there atm.

@Vishal-Joshi
Copy link

What is this 'formats' object? @jmnsf

@jmnsf
Copy link
Contributor Author

jmnsf commented Apr 1, 2016

The argument to res.format, has all your handlers per format.

@Vishal-Joshi
Copy link

No, I am asking about the 'formats' object which you are assigning to httpMocks.createResponse().format? @jmnsf

@howardabrams
Copy link
Collaborator

I could really use some help on this one. Would either of you like to attempt a pull request with your approach? Tests to explain how it should be used would be great too!

jmnsf added a commit to jmnsf/node-mocks-http that referenced this issue Aug 1, 2016
Signed-off-by: jmnsf <jmnsferreira@gmail.com>
howardabrams added a commit that referenced this issue Aug 2, 2016
Adds .format to the response object. Closes #94.
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

3 participants