When testing models, you can use Ember Data to help. In this recipe, we'll create a model and test to make sure that it's creating data correctly.
In a new application, generate a new student model:
$ ember g model student.js
This will generate the necessary files for the student model.
Update the student model with two properties:
// app/models/student.js import DS from 'ember-data'; export default DS.Model.extend({ firstName: DS.attr('string'), lastName: DS.attr('string') });
This model has two properties,
firstName
andlastName
. Both holdstring
values.Add a new unit test for the new model that tests the new properties:
// tests/unit/models/student-test.js import { moduleForModel, test } from 'ember-qunit'; moduleForModel('student', 'Unit | Model | student', { // Specify the other units that are required for this test. needs: [] }); test('it exists', function(assert) { let model = this.subject(); assert.ok(!!model); }); test('Test model...