ember.jsember-cliacceptance-testing

How to get the LAST element in a list for Ember Acceptance Testing


When writing Acceptance tests, does anyone happen to know how one would select the LAST element in a list? I am testing the act of adding a new record to a list and would like to edit/delete the newly created record in my test.
I've tried to select the newly created record like this....

let newRecordLink = find('div.parent-list .list-group-item').last();
click(newRecordLink);

Which sorta works. It pulls the last element, but it busts out of my test and suddenly I'm on the actual page of the app I'm trying to test instead of remain within the test container.

Here is the relevant HBS code:

<div class="list-group parent-list">
  {{#each model.owners as |item|}}
    {{#link-to 'client.members.edit-owner' item.id class="list-group-item" id=item.id}}
      <h4 class="list-group-item-heading">
        {{item.firstName}} {{item.lastName}}
      </h4>
    {{/link-to}}
  {{/each}}
</div>

Solution

  • You can use :last selector (https://api.jquery.com/last-selector/)

    click('div.parent-list .list-group-item:last')