Acceptance test for outgoing requests

I want to write test for checking whether my post, patch, delete calls are going to backend. This transitions are not causing any front-end changes. Does anyone have any idea to do this ??

The easiest way to do this kind of thing is to use Mirage (or just Pretender, which Mirages uses under the hood). In each test you can set up the endpoint that you want to hit, set up any prerequisite state, perform the actions needed via the test helpers, and then verify that the endpoints were hit. There are multiple ways to do that last part, the simplest is to just put assert calls in your route handler itself but you could also use spies or something like that.

@dknutsen thank you for your replay. I also want to know is there a way to test POST request without mirage. I mean test with expecting a server response(like status code 201)

Well the way I see it you have basically two options:

  1. use a “fake backend”, something like mirage or pretender, etc that intercepts the requests and handles them client-side
  2. use a “real backend”, where your test actually makes a full request. This requires a much more robust framework for end to end testing.

The ember testing support is meant for front-end only tests which is why mocking with mirage is the preferred solution. That said end-to-end tests are often very valuable so many companies choose to do a mix. At my last company we had a very robust suite of Ember tests for our Ember app and then we also had end-to-end tests for critical functionality and some other “whole system” functions in Selenium

EDIT: also note that end to end testing is probably going to be way slower so it’s best to use it more sparingly and/or in a totally separate CI process, etc.

1 Like

With mirage you can choose to let certain requests pass through to the network. So you could definitely write a test for this. But since the API response cannot be controlled by the test in this case, your test will not be deterministic.

For the more robust option, there is this:

It’s cross browser, which is harder to come by than you’d think from a tool that does this kind of testing.