Writing Unit Tests

You’ll learn how to write unit tests for an Ember application in this lesson.

We'll cover the following

A unit test sits at the lowest level of the testing pyramid, and it tests the entity, more informally the thing, in isolation. Some of the pieces of Ember apps that we have covered that are suitable for unit testing are services, controllers, and models.

One of the small details I like about Ember’s kick-ass, in my opinion, testing story is that you don’t have to know which type of test to write for a specific piece of your application as long as there’s a blueprint for it. You just tell which piece you write the test for. This was the case for components, and it’s the same for services.

Creating a service test

Since we want to write a test for a service, we simply generate a service test:

ember g service-test catalog

Next, we test that the add method is working correctly, both for bands and songs:

Get hands-on with 1200+ tech skills courses.