Api calls getting redirected (Moved Temporarily) using Ember-cli, ember test --server, and http-mock


I have some http-mock request/responses I’d like to use only in a testing environment. Our API is completely built out, so I’d only like to use the mocks when running ‘ember test --server’ or ‘ember test’ (CI mode). I’m running into a few issues setting this up and was hoping someone had a solution.

When I run 'ember test --server ', tests run at an url that’s like http://localhost:7357/7150/tests/index.html

However, any time a request to the backend is made I get a 302 Moved Temporarily response. For example, when the client does a GET to what I would expect would be my data endpoint url in this testing mode: http://localhost:7357/brands/1, I get the 302 response and the url is redirected to http://localhost:7357/brands/1/test/index.html (which does not exists)

the mock works fine when I run tests in a browser using port 4200, ie

I think I’m missing some magic configuration somewhere. Anyone know how I can get my ‘ember test --server’ to utilize my mocked out backend using ember-cli’s http-mocks?


I’m getting the same, did you have any luck working this out?


This SO post had the answer: http://stackoverflow.com/questions/24053248/how-to-get-test-to-access-ember-cli-server-when-run-in-ci-mode

And this commit demonstrates it: https://github.com/voluspa/vilive/commit/948962e2e0cfd1a11c4f47bd9438007d505c8d77

You need to tell ember test to hit a running Ember server (which you have made accept CORS), which proxies the request to your test server (e.g. Rails).

Or you could get your test server to accept CORS directly instead.


thanks. we ended up using Pretender to always stub out api calls in our tests instead


Have a look at https://github.com/samselikoff/ember-cli-mirage/.

We were also using http-mock + Pretender combo earlier. Recently moved to ember-cli-mirage, which works flawlessly and gives you best of both.