O'Reilly logo

Mastering Ember.js by Mitchel Kelonye

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing unit tests

Unit testing involves testing object-computed properties, observers, and method calls.

Testing computed properties

Let's start by looking at the first tested object-computed property in the chapter sample, the total property of App.CartItem, that is applied from App.TotalMixin:

App.CartItem = Em.Object.extend(App.TotalMixin, { 
  product: null, 
  quantity: null, 
  price: null 
});

When a user clicks on the order button of a meal, we expect the cart to be filled by the new item. We also expect the item's total property to be incremented, which is ascertained as follows:

describe('App.CartItem', function() { describe('total', function(){ beforeEach(App.beforeEach); afterEach(App.afterEach); it('should be computed from .price and .quantity', ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required