3

I'm testing an Ember app and I've got a link inside a table.

I can get to the link by the selector:

$('tr:nth-child(1) td:nth-child(3) a')

In my test I have:

click($('tr:nth-child(1) td:nth-child(3) a'));

But after doing console.log(currentURL()); I am not on the link that the above click should have taken me to.

Do I need to be more specific with the link to click? Or am I using click wrong? Or is there a different test helper I should be using?

James White
  • 535
  • 10
  • 24

2 Answers2

0

click is an asynchronous method, you need to wait for it to complete before attempting to view the results.

click($('tr:nth-child(1) td:nth-child(3) a'));
andThen(function(){
  console.log(currentURL());
});

or

click($('tr:nth-child(1) td:nth-child(3) a')).then(function(){
  console.log(currentURL());
});
Kingpin2k
  • 47,277
  • 10
  • 78
  • 96
  • I've tried the first suggestion, and just tried it again and the same thing happens. It doesn't go to the URL in the link. The second doesn't return anything and the console.log is never triggered. I put it in an alert and that didn't activate either. The test says Object not found. – James White Oct 03 '14 at 20:32
  • 1
    Is it outside of your ember app? – Kingpin2k Oct 03 '14 at 21:15
  • It's in my testing suite along with my other tests. – James White Oct 04 '14 at 00:43
  • I mean the anchor tag, is it part of a template inside of the app. – Kingpin2k Oct 04 '14 at 07:13
  • Yes. I can put in $('tr:nth-child(1) td:nth-child(3) a') in the dev console and it will highlight the link on the page. – James White Oct 05 '14 at 01:59
0

I am having this exact problem. In the Ember app, I can click on the tag and a modal dialog pops up, as expected. In the test I'm writing for this modal, nothing seems to work. I can type

Ember.$('#id-of-tag').click();

on the JS console, and the modal appears. I paste that into the test and nothing happens. I've tried click(find('#id-of-tag')[0]) too.

We're using Ember 2.7.3 but will switch to 2.12 very soon.

Berry
  • 1,719
  • 2
  • 11
  • 15