mardi 23 juin 2015

Qunit acceptance test for Ember.JS app passing in browser but failing in CLI via PhantomJS

I'm working through the Ember-CLI-101 ebook and have a small issue, I've gotten around to writing acceptance (integration/feature) tests and I've got a test that goes to the root path and then click a link on the header and then fill in a form.

It works when I go to http://localhost:4200/tests but when I do ember test in the CLI it fails with the following error:

actual: >
false
expected: >
true
message: >
Error: Element a[href="/friends/new"] not found.
Log: >

I assume this is some kind of PhantomJS issue with the page not loading properly but it could be anything I suppose. I'm having a hard time finding a solution on the web and would appreciate any help please.

The test:

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

var application;

module('Acceptance | friends/new', {
  beforeEach: function() {
    application = startApp();
  },

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

test('creating a new friend', function(assert){
  visit('/');
  click('a[href="/friends/new"]');

  andThen(function(){
    assert.equal(currentPath(), 'friends.new');
  });
  fillIn('input[placeholder="First Name"]', 'Johnny');
  fillIn('input[placeholder="Last Name"]', 'Cash');
  fillIn('input[placeholder="email"]', 'j@cash.com');
  fillIn('input[placeholder="twitter"]', 'jcash');
  click('input[value="Save"]');

  andThen(function(){
    assert.equal(
      currentRouteName(),
      'friends.show.index',
      'Redirects to friends.show after create'
    );
  });
});

This is the header on the page:

<nav>
  {{link-to "Ember-Borrowers" "index" class="main"}}

  <input id="bmenu" class="burgercheck" type="checkbox">
  <label for="bmenu" class="burgermenu"></label>

  <div class="menu">
    {{link-to "Dashboard" "index" class="icon-gauge"}}
    {{link-to "Friends" "friends" class="icon=users-1"}}
    {{link-to "New Friend" "friends.new" class="icon-user-add"}}
  </div>
</nav>

This is the HTML generated:

<a id="ember471" class="ember-view icon-user-add" href="/friends/new">New Friend</a>

As I say, it passes in the browser.




Aucun commentaire:

Enregistrer un commentaire