5
votes

I have a problem in my app where 2 acceptance-tests seem to conflict. If I run the tests one of the 2 tests will fail. The next time I run it the other will fail and so on. They never fail if run one by one..

The first test is testing that visiting a url will redirect to the right path based on whether a model has any records in its toMany-relationship (async). This test fails with: Error: Assertion Failed: Cannot call get with 'currentPath' on an undefined object.

The second test is a test that checks if the toMany relationship is rendered in an unordered-list. This test fails because the content of the list-item is empty.

These are my tests:

test('visiting /categories/#', function() {
  visit('/categories/1');

  andThen(function() {
    equal(currentPath(), 'categories.category.subcategories.index');
  });
});

test('renders products', function () {
  visit('/categories/2/products');

  andThen(function () {
    var list = find('#product-list li');
    equal(list.length, 2);

    var first = find('#product-list li').eq(0);
    equal(first.text(), 'A4');

    var last = find('#product-list li').eq(1);
    equal(last.text(), 'A3');
  });
});

Full code

Running app

Running tests

Update:

Upgraded to latest ember-cli 0.0.43 now the first test fail is gone (npm install --save-dev ember-cli), but still the second test fails every second time i run the tests..

1
I have a similar problem... did you solved it? Or is it still unresolved? - tschoartschi

1 Answers

0
votes

My guess is that the first time you visit the page, the model is not yet available and is requested from the backend.

In your test, you do not wait for the model to become available and access the page when it's rendered with no records.

You use jQuery to retrieve content from HTML elements. When elements are not available, jQuery silently produces an empty collection that would always return empty values. Thus, failing test.