I would rather make a component that takes data as props. Now make a component on top that runs a network request and injects the network response into it. Now you have a reusable component independent of the api. Your network function can be tested individually. Your top level component doesn’t need testing as that is the part that would be mocked. You can now test your actual component without any mocking. If you n…
MirageJS: An API mocking library for frontend development
21–30 of 52 posts
Re: MirageJS: An API mocking library for frontend development
#22Hello! I'm Sam and I built Mirage JS to be a framework-agnostic API mocking library. Mirage is extracted it from an addon that's been widely used in the Ember ecosystem for the past 4 years, at companies like Apple, Heroku, Square and Footlocker. Nearly all frontends need to talk to an API, no matter what framework they're built with! So over the past year I've made Mirage work with any tool or test runner. I really…
Re: MirageJS: An API mocking library for frontend development
#23I believe Michael Feathers was just started a Twitter thread yesterday that talked, among other things, about moving IO to the edges of your code. If you can divide acquisition from usage, I wonder how much less effort you need to put into API mocking. Ages ago and shortly after I started testing, was the last time I had to do any low-level HTTP response processing. My coworkers could not fathom why I had divided the…
Yes! Yes! Yes! I've been preaching this approach ever since watching Gary Bernhardt's talk on "Boundaries" [1]. Splitting conditional logic from dependencies makes code so much easier to test. If you can do that, there's no need to mock anything. You can just pass simple data objects into your conditional logic for testing, and use a handful of integration tests to validate the end-to-end flow. [1] https://www.destro…
With the exception of callbacks (and async solves that for single-issue scenarios), arguments don't need to be mocked. They're just arguments.
Re: MirageJS: An API mocking library for frontend development
#24Hello! I'm Sam and I built Mirage JS to be a framework-agnostic API mocking library. Mirage is extracted it from an addon that's been widely used in the Ember ecosystem for the past 4 years, at companies like Apple, Heroku, Square and Footlocker. Nearly all frontends need to talk to an API, no matter what framework they're built with! So over the past year I've made Mirage work with any tool or test runner. I really…
Re: MirageJS: An API mocking library for frontend development
#25Hello! I'm Sam and I built Mirage JS to be a framework-agnostic API mocking library. Mirage is extracted it from an addon that's been widely used in the Ember ecosystem for the past 4 years, at companies like Apple, Heroku, Square and Footlocker. Nearly all frontends need to talk to an API, no matter what framework they're built with! So over the past year I've made Mirage work with any tool or test runner. I really…
Phenomenal landing page. The first text I read is a ~10-word description of the value proposition. The next thing my eyes are drawn to is a visual demo. The first thing I can click is a link to use it myself. Plus, it's all visually very appealing without being distracting. Well done.
Re: MirageJS: An API mocking library for frontend development
#26Instead of
// MyComponent.js
const users = await fetch(...
Use this // MyComponent.js
const users = await api.getUsers()
// api.js
export default {
getUsers() {
return fetch(...
}
}
To mock, you replace the entire api module (or individual functions).Re: MirageJS: An API mocking library for frontend development
#27Glad to see something like mirage solving this across all different types of API frameworks.
Re: MirageJS: An API mocking library for frontend development
#28Colorizing[1] the console logs for quickly parsing success and failure might be a nice addition. [1]: https://developers.google.com/web/tools/chrome-devtools/cons...
edit: grammar
Re: MirageJS: An API mocking library for frontend development
#29What is the benefit of a request mocking framework versus hiding all api requests behind a module? Instead of // MyComponent.js const users = await fetch(... Use this // MyComponent.js const users = await api.getUsers() // api.js export default { getUsers() { return fetch(... } } To mock, you replace the entire api module (or individual functions).
https://miragejs.com/docs/getting-started/introduction
"Use a client-side interceptor to handle your app's network requests. ... This is the most flexible approach, but it requires you to start from scratch in each project, and leaves it up to you to enforce conventions across your apps."
"Importantly, because Mirage mocks the HTTP boundary instead of the JavaScript code your app uses to make network requests, you never need to modify your application code to account for whether your app is talking to Mirage or to your real production backend."
Re: MirageJS: An API mocking library for frontend development
#30Working on a React project recently, I was surprised that there wasn't an option like mirage, but now that there is, I highly recommend it!