-
Notifications
You must be signed in to change notification settings - Fork 48
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
Refactor adapters #76
Conversation
expect(request.status).toEqual(418); | ||
// @ts-ignore | ||
expect(request.responseText).toEqual( | ||
'{"data":[{"id":1,"name":"foo"},{"id":2,"name":"bar"}],"status":200}', | ||
); | ||
}); | ||
|
||
it('should pass request in response interceptor', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! 🔥
const adapter = new MswAdapter({ server }); | ||
const handler = adapter.getHandler(); | ||
``` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO we should go a bit further and at least mention the required methods of a Server
object and their input/output
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise 🔥
README.md
Outdated
Intercept AJAX calls to fake a REST server based on JSON data. Use it on top of [Sinon.js](http://sinonjs.org/) (for `XMLHTTPRequest`) or [fetch-mock](https://github.com/wheresrhys/fetch-mock) (for `fetch`) to test JavaScript REST clients on the browser side (e.g. single page apps) without a server. | ||
A browser library that intercepts AJAX calls to mock a REST server based on JSON data. | ||
|
||
Use it on top of [Sinon.js](http://sinonjs.org/) (for `XMLHttpRequest`) or [fetch-mock](https://github.com/wheresrhys/fetch-mock) (for `fetch`) to test JavaScript REST clients on the browser side (e.g. single page apps) without a server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Promote fetch and MSW first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Problem
To reuse the adapters with a different REST dialect, developers must rewrite everything.
Also, middlewares are adapter-specific.
Solution
Use dependency injection instead of inheritance for server logic.
Rename servers to adapters
TODO