0
votes
import Ember from 'ember';
import startApp from '../../helpers/start-app';

var App;

module('Integration | Authentication | Abilities', {
  integration: true,
  setup() {
    App = startApp();
  },
  teardown() {
    Ember.run(App, 'destroy');
  }
});

test('Only SuperUsers, Researchers and AccountHolders can see messages', function(assert) {
  visit('/');
  assert.equal(find('div').text(), 'fsfsfd');
});

This is an integration test I'm trying to get working so I can test basic user interaction in our ember-cli app. The problem is that this simple test does only returns empty strings whenever I search the DOM. It is not hitting an unauthorized page or anything it's just returning nothing from any testHelpers. currentURL, currentPath return undefined.

Am I missing something absolutely fundamental in my understanding of how integration tests work?

I'm trying to test how ember-can gives and denies permissions to users based on their title. However, I may as well just be testing whether or not the logo shows up in the right corner because I can't see anything on the page at the moment.

2

2 Answers

0
votes

I think what you're missing is that tests are asynchronous. Transitions involve promises (typically loading models) so you need to wait for the visit to complete. You can use the andThen helper:

test('Only SuperUsers, Researchers and AccountHolders can see messages', function(assert) {
  visit('/');

  andThen(function() {
    assert.equal(find('div').text(), 'fsfsfd');
  });
});

Here's more info in the guides

0
votes

I'm posting because it turns out the problem was the way our website had been set up with a rootURL. I had to put this line inside our startApp.js file: setResolver(Ember.DefaultResolver.create({ namespace: "/cli/ea/" }));

It looks like the resolver was taking me to localhost:4201/ which is not actually going to be used because we are proxying from rails (which is localhost:3000). Therefore, nothing was coming back from any DOM interaction because there was no route and no template set. currentURL and other helpers returning undefined I guess was the only piece that was unusual in hindsight.