Question

I'm using AngularJS 1.2.10 with ng-tables and I'm writing my first end to end tests using jasmine & karma.

The problem is when I type in a filter input box (provided by ng-table) the listing in my tests is not automatically updated, ie: it's not running the filter in tests. I does work when I manually test it through a browser though.

Here is my test

  it "should allow filtering on name", ->
    browser().navigateTo('#/debtors')
    expect(browser().location().path()).toBe("/debtors")
    element(".ng-table-filters > th:nth-child(2) input").val('John')
    sleep(10)
    expect(repeater('.table > tbody tr').count()).toBeGreaterThan(0)
    expect(repeater('.table > tbody tr').row(0)).toContain("John Smith")

Here is my filter code:

<table ng-table="tableParams" show-filter="true" class="table">
  <button ng-click="tableParams.sorting({code: 'asc'})" class="btn btn-default pull-right">Clear sorting</button>
  <button ng-click="tableParams.filter({})" class="btn btn-default pull-right">Clear filter</button>
  <tr class='listing' ng-repeat="debtor in $data">
    <td data-title="'Code'" sortable="'code'" filter="{ 'code': 'text'}">
      {{debtor.code}}
    </td>
    <td data-title="'Name'" sortable="'name'" filter="{ 'name': 'text'}">
      {{debtor.name}}
    </td>
    <td>
      <a href="/api#/clients/{{debtor.id}}">Show</a>
      <a href="/api#/clients/{{debtor.id}}/edit">Edit</a>
      <a href="" ng-confirm-click="destroy(debtor.id)">Delete</a>
    </td>
  </tr>
</table>

When testing it manually there is a slight pause before the results are displayed, I don't have to hit any submit buttons. When I do this in tests though it seems like the ngTable event is not firing.

Was it helpful?

Solution

I started using protractor instead which better suites AngularJS projects

describe('filter debtor', ->

  beforeEach ->
    helper.login()

  afterEach ->
    helper.logout()

  describe "when person", ->
    it 'shows the client after creation', ->
      browser.get('/api#/clients/new_debtor')
      element(By.id("name")).sendKeys("John")
      element(By.id("surname")).sendKeys("Smith")
      element(By.id("create_btn")).click()

      browser.get('/api#/debtors')
      element.all(By.model("params.filter()[name]")).last().sendKeys("John")
      first=element.all(By.id("listing")).first()
      expect(first.getText()).toContain("John Smith")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top