AJP
AJP

Reputation: 545

Disable Ember Mirage when running tests in the browser

I would like to be able to run tests against my Mirage server, and my actual server in turn.

I've read these docs on disabling Mirage, and it works as expected for the development environment. Adding the code below disables Mirage at http://localhost:4200.

 ENV['ember-cli-mirage'] = {
    enabled: false
  };

However, this does not disable mirage when running tests in the browser at http://localhost:4200/tests.

I have added the code above outside of any of the environment specific conditionals, so it should apply to all environments. For good measure, I have also tried adding the code above inside each of the three environment specific conditionals as well:

 ENV['ember-cli-mirage'] = {
    enabled: false
  };

if (environment === 'production') {
  ENV['ember-cli-mirage'] = {
    enabled: false
  };
}
if (environment === 'development') {
  ENV['ember-cli-mirage'] = {
    enabled: false
  };
}
if (environment === 'test') {
  ENV['ember-cli-mirage'] = {
    enabled: false
  };
}

http://localhost:4200/tests still uses Mirage.

Is there a way to disable Mirage when testing in the browser? I would like to be able to enable it easily, so uninstalling Mirage is not an option.

Upvotes: 0

Views: 641

Answers (2)

AJP
AJP

Reputation: 545

I had misunderstood the effect of adding setupMirage(hooks); in and acceptance test. (docs here)

When it is present in your acceptance test, all requests will go to mirage, whether or not ENV['ember-cli-mirage'].enabled is true or false.

Conversely, when it is absent, all requests will be sent to your defined endpoint, whether or not ENV['ember-cli-mirage'].enabled is true or false.

This may explain why the docs on enabling or disabling mirage only refer to doing to for the production and development environments.

Upvotes: 3

emare
emare

Reputation: 54

Your code looks fine to me. Maybe restarting the server would help as @jrjohnson suggested. If that didn't work, configuring the environment.js file like so might help:

module.exports = function(environment) {

  let ENV = {
    'ember-cli-mirage': {
      enabled: true,
      directory: 'mirage'
    }
  };

  if (environment === 'test') {
    ENV['ember-cli-mirage'].enabled = false;
  }

  return ENV;
};

Upvotes: 0

Related Questions