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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With