I am attempting to write a test in my ember-cli application that tests whether a particular controller action will take the user to a specific route based on the value of an input on the page.
Here's the error I'm getting:
IndexController: the setTable action navigates to the tables route
✘ Died on test #1 at http://localhost:7357/assets/qunit.js:425
at test (http://localhost:7357/assets/vendor.js:72425)
at :29
at http://localhost:7357/assets/vendor.js:54
at http://localhost:7357/assets/test-loader.js:14: 'null' is not an object (evaluating 'target.transitionToRoute')
If I attempt it in the browser this is the error I get in the console:
Error while loading route: undefined
My route is defined, here's my router:
import Ember from 'ember';
var Router = Ember.Router.extend({
location: AccelewaiterENV.locationType
});
Router.map(function() {
this.route('table', { path: '/table/:table_id' });
});
export default Router;
Here's my test:
import { test, moduleFor } from 'ember-qunit';
moduleFor('controller:index', 'IndexController', {
// Specify the other units that are required for this test.
// needs: ['controller:foo']
});
test('the setTable action navigates to the tables route', function() {
var controller = this.subject();
controller.set('tableNumber', 1);
controller.send('setTable');
ok(controller.get('currentPath') === '/table/1');
});
Here's my template:
<div class="start">
<div class="row">
<div class="col-xs-12">
{{input type="text"
valueBinding="tableNumber"
class="form-control input-lg"
placeholder="Enter Table #"}}
<button {{ action 'setTable' }}
id="submit-table"
class="btn btn-success">Ok</button>
</div>
</div>
</div>
And here's my controller:
import Ember from 'ember';
export default Ember.Controller.extend({
tableNumber: null,
actions: {
setTable: function() {
var tableNumber = this.get('tableNumber');
console.log(this.transitionTo);
this.transitionToRoute('table/' + tableNumber);
}
}
});
I also have a table controller created, it's currently empty though.
Any help greatly appreciated!