Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to simulate back button when testing Ember.js apps?

In my acceptance tests, I would like to simulate the back button click and results transitions.

I have the following, but I have a feeling that its wrong.

test("back to search page", function(){
  visit('/')
    .then(function(){
      return fillIn('.search input', 'hi');
    })
    .then(function(){
      return click('.search button');
    })
    .then(function(){
      // I want to go back here
      return visit('/');
    })
    .then(function(){
      var keyword = find('.search input').val();
      equal(keyword, '');
      ok(!exists('.search .results'));
    });
})

What's the right way to simulate back button in tests?

like image 785
Taras Mankovski Avatar asked Sep 21 '13 00:09

Taras Mankovski


2 Answers

window.history.back() or window.history.go(-1)

like image 121
alexspeller Avatar answered Sep 19 '22 21:09

alexspeller


To make window.history.back() work you need to use location : 'hash' in your Router

App.Router.reopen({
  location: 'hash'
});

Here's the official documentation about setting the location type: http://emberjs.com/guides/routing/specifying-the-location-api/

like image 30
Jeremy Green Avatar answered Sep 23 '22 21:09

Jeremy Green