Inconsistent acceptance tests

I have a problem in my application where 2 acceptance tests seem to conflict. If I run the tests, one of the two tests will fail. The next time I run it, the other will fail and so on. They never crash if they run one after another.

The first test is testing that the visit to the URL will be redirected to the correct path based on whether the model has any entries in its toMany relationship (async). This test fails: Error: Validation failed: Unable to call get with "currentPath" in the undefined object.

The second test is a test that checks if the toMany relation is displayed in an unordered list. This test failed because the contents of the list item are 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

Application launch

Running tests

Update:

Updated to the latest version of ember-cli 0.0.43 now the first test failure (npm install --save-dev ember-cli), but the second test fails every second time I run the tests.

+5
source share
1 answer

I assume that on the first visit to 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 gain access to the page when it is rendered without records.

You use jQuery to extract content from HTML elements. When items are not available, jQuery seamlessly creates an empty collection that always returns empty values. Thus, a failed test.

0
source

Source: https://habr.com/ru/post/1201044/


All Articles