Josh Smith
Josh Smith

Reputation: 15028

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?

Upvotes: 5

Views: 979

Answers (1)

Balint Erdi
Balint Erdi

Reputation: 1143

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.

Upvotes: 4

Related Questions