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

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

In my tests, I try to use Pretender to mock responses to API requests, but Pretender does not handle requests, I suspect because of this custom host setting.

I tried many different options to do this work, including setting the host to different values, and not setting the host at all, running tests using the --proxy , etc.

I obviously just throw darts on the wall and hope something sticks. Can someone help me figure out what I should do?

+5
source share
1 answer

This might work if you define the host of your adapter as a configuration variable:

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

You define the host as the "real" host in hostless environments ( http: //api.lvh.mehaps000) and just omit config.apiHost for testing. If you do this, you can use Pretender to interrupt requests, since they are now the same (or, in other words, relative) requests.

+3
source

Source: https://habr.com/ru/post/1202189/


All Articles