Check out a free preview of the full Ember 2.x course:
The "Exercise 9" Lesson is part of the full, Ember 2.x course featured in this preview video. Here's what you'd learn in this lesson:

In this exercise, you will build a “nice-number” Handlebar helper. You will also write a unit test for this new helper.

Get Unlimited Access Now

Transcript from the "Exercise 9" Lesson

>> [MUSIC]

>> Mike North: I want to build a helper that does the following, so we've got in our GitHub repost Component, GitHub repo Component I should say, we have account for the number of watchers and the number of forks. And some of these are big numbers. And I wanna express those, if the number is greater than 1000 as 2.6k instead of 2592, so just round reasonably.

[00:00:39] But the point of the exercise is to use a helper here to sort of format this number nicely and then we can use it throughout our app to kind of have a very consistent way of representing a large number. And it's common to do this with dates and with currencies.

[00:00:59] This is great, great way to use a helper. And because we have testing under our belt now, I'd like some unit test coverage. And this is very easy to test with a unit test because, unlike a computed property where we have to create an object and to have to place that property on an object, here, if we look at my example, all you need to do is pass in an array of parameters representing in order the unnamed arguments, so you would pass in one and then framework.

[00:01:35] And then you should get a string returned from that function. That is what you expect. So this can be tested without adding it to an object you should just be able to test it right away