Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Pretender in an ember-cli app with a custom hostname

I extend the DS.ActiveModelAdapter to use a custom host since my API is on a subdomain, using, for example, http://api.lvh.me:3000 when working locally.

In my tests I try to use Pretender to mock the responses to the API requests, but Pretender isn't handling the requests, I suspect due to this custom host setting.

I've tried many different variations to make this work, including setting the host to different values, not setting the host at all, running the tests with the --proxy command, and so on.

I'm obviously just throwing darts at a wall and hoping something will stick. Can anyone guide me to understanding what I should be doing?

like image 288
Josh Smith Avatar asked Sep 29 '22 22:09

Josh Smith


1 Answers

It might work if you define the host of your adapter as a config variable:

export default DS.ActiveModelAdapter.extend({
  host: config.apiHost
});

You define host to be the "real" host in non-hosting environments (http://api.lvh.me:3000) and just omit the config.apiHost in testing. If you do so, you can use Pretender to stub out the requests since they are now same-host (or, in other words, relative) requests.

like image 138
Balint Erdi Avatar answered Oct 25 '22 06:10

Balint Erdi