Controllers should be tested in your application. In this recipe, we'll test some basic actions from a controller.
Create a new
index
controller:$ ember g controller index
This creates a new controller called
index
.In the index controller, add a new property and action:
// app/controllers/index.js import Ember from 'ember'; export default Ember.Controller.extend({ myValue: 'value', actions:{ pressed(value){ this.set('myValue',value); } } });
This controller has one property named
myValue
. Another action calledpressed
changes the value ofmyValue
to whatever value is passed in the function.Update the index unit test. Add a few tests for the action and property:
// tests/unit/controllers/index-test.js import { moduleFor, test } from 'ember-qunit'; moduleFor('controller:index', 'Unit | Controller | index', { // Specify the other units that are required for this test. // needs: ['controller:foo'] }); // Replace this...