5

This has been an annoying problem for days now. As I start to try to write acceptance tests for my Ember app, when I use the visit() function, the URL is changed in the browser's address bar, so when I change a bit of code and the liveReload happens, it navigates off my test page to whatever page I had told it to visit in the tests.

To troubleshoot, I ember new'd a new app, created a /home route and template, and created an acceptance test for it, and it passed fine, without changing the URL in the address bar. I've compared the code in tests/helpers and it's the same, as is tests/index.html.

I've searched all over without coming across an answer. It's been hard enough for me to grok testing, but problems like this are just tangential, but very irritating. If anyone has a tip as to why this is happening, I'd be extremely grateful for a fix.

As an example, here's my one acceptance test. It passes, but the URL actually changes:

import Ember from 'ember';
import { module, test } from 'qunit';
import startApp from 'star/tests/helpers/start-app';

var application;

module('Acceptance: AddMilestone', {
  beforeEach: function() {
    application = startApp();
  },

  afterEach: function() {
    Ember.run(application, 'destroy');
  }
});

test('Adding milestones', function(assert) 
  visit('/projects/1234567/details');

  andThen(function() {
    assert.equal(currentPath(), 'project.details');
  });
});
redOctober13
  • 3,662
  • 6
  • 34
  • 61
  • I have found that if you do any redirecting in your Routes it will break acceptance testing and you will need to run a separate cli server on a different port and with the environment flag set to 'test' as per the comments below. The key to understanding what causes the issue is realizing it is the Routes in your app that are breaking the acceptance tests due to location type being whatever you set it to in 'development' mode... – Christopher Milne Oct 07 '15 at 15:03

1 Answers1

6

Look in config/environment.js for a block similar to this:

if (environment === 'test') {
  // Testem prefers this...
  ENV.baseURL = '/';
  ENV.locationType = 'none';

  // keep test console output quieter
  ENV.APP.LOG_ACTIVE_GENERATION = false;
  ENV.APP.LOG_VIEW_LOOKUPS = false;

  ENV.APP.rootElement = '#ember-testing';
}

Is ENV.locationType set to none for your test environment?

If not, are you changing the locationType elsewhere in your app? Setting it to none leaves the address bar alone.

Chris Peters
  • 17,918
  • 6
  • 49
  • 65