Unit Testing Basics

Unit tests are generally used to test a small piece of code and ensure that it
is doing what was intended. Unlike acceptance tests, they are narrow in scope
and do not require the Ember application to be running.

As it is the basic object type in Ember, being able to test a simple
EmberObject sets the foundation for testing more specific parts of your
Ember application such as controllers, components, etc. Testing an EmberObject
is as simple as creating an instance of the object, setting its state, and
running assertions against the object. By way of example, let's look at a few
common cases.

Testing Computed Properties

Let's start by creating an object that has a computedFoo computed property
based on a foo property.

See that we have used moduleFor, one of the several unit-test helpers provided by Ember-Qunit.
Test helpers provide us with some conveniences, such as the subject function that handles lookup and instantiation for our object under test.
Note that in a unit test you can customize the initialization of your object under test by passing to the
subject function an object containing the instance variables you would like to initialize. For example, to initialize
the property 'foo' in our object under test, we would call this.subject({ foo: 'bar' });

Testing Object Methods

Next let's look at testing logic found within an object's method. In this case
the testMethod method alters some internal state of the object (by updating
the foo property).

In the event the object's method returns a value, you can simply assert that the
return value is calculated correctly. Suppose our object has a calc method
that returns a value based on some internal state.