Note: This is a repost of my Fail Mail newsletter.
On April 20th I wrote some tests at work. For some reason, I just could not understand why they didn’t pass. Everything looked correct and the functionality did work in a non-test environment. I decided to just walk away from the code and clear my mind and then it occurred to me: This mock API response I made for the test didn’t follow the JSON:API spec.
And I have to be honest here. I love writing tests but I hate writing mock API because it often leads to issues like this.
The problem with mock APIs for frontend testing is that you ask frontend developers to literally maintain a copy of the real API. However, it usually doesn’t get the same priority as the normal API which means you’re often left with a mock API in a weird state.
And this did cause failing on my part. I didn’t see that this wasn’t living up to the spec and would cause my test to fail. And I spent so, so long debugging.
Since then we have actually moved to a test tool called Polly.js by Netflix. This has helped me deal with the mock API for now, but I still see these issues a lot with other developers.
I do think it’s a bit harmful to expect frontend developers to maintain a separate API. It’s just bound to fail at some point.
Want to read more like this? Subscribe to Fail Mail!
Do you want to share your fails with me and the Fail Mail community? Write a comment or write me on Twitter (My DMs are open) and I'll include your fails in the next newsletter.