Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Acceptance tests in Ember.js change the URL in the address bar

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');
  });
});
like image 615
redOctober13 Avatar asked Jun 22 '15 19:06

redOctober13


1 Answers

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.

like image 86
Chris Peters Avatar answered Sep 23 '22 00:09

Chris Peters