Unit tests are used to test smaller chunks of functionality. In this recipe, we'll see an example of this.
In this example, we'll create a simple Ember.Object
with a computed property. We'll test this computed property and assert if the value returned is correct or not.
In a new project, create a new
first-last.js
file in themodels
folder:// app/models/first-last.js import Ember from 'ember'; export default Ember.Object.extend({ firstName: 'John', lastName: 'Smith', fullName: Ember.computed('firstName', 'lastName', function() { const firstName = this.get('firstName'); const lastName= this.get('lastName'); return `Full Name: ${firstName} ${lastName}`; }) });
In this file, we have two properties,
firstName
andlastName
. ThefullName
computed property combines these two and returns a full name. If either of these properties change, the computed property will fire.Create a new unit test that checks
Ember.Object
andcomputed
property...