Testing routes can be done either by acceptance tests or unit tests. In this example, we'll create a simple unit test for a route.
students
route:$ ember g route students
This command will generate the route code for students.
// app/routes/students.js import Ember from 'ember'; export default Ember.Route.extend({ someText: 'someText' });
This route has a property called someText
.
students-tests.js
file in the tests/unit/routes
folder:// tests/unit/routes/students-test.js import { moduleFor, test } from 'ember-qunit'; moduleFor('route:students', 'Unit | Route | students', { // Specify the other units that are required for this test. }); test('check prop and route exists', function(assert) { let route = this.subject(); assert.expect(3); assert.equal(route.get('someText'),'someText'); route.set('someText','otherText'); assert.equal(route.get('someText'),'otherText'); assert.ok(route); });
In this example, we are checking the output of the someText
property. The first
assert.equal
gets the property and checks it against the someText
value. The route instance can also set properties. The next assert checks to see whether the new value has been set. The final assert makes sure that the route is available.
ember server
and navigate to /tests
: