Ember 2.x Ember 2.x

Exercise 8 Solution, Part 3

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

Now that the is-in-array test is created, Mike adds a test for the favorite/unfavorite action.

Get Unlimited Access Now

Transcript from the "Exercise 8 Solution, Part 3" Lesson

[00:00:00]
>> [MUSIC]

[00:00:04]
>> Mike North: The next thing I wanna do is fire an action. The way we're gonna do that is by clicking on the favorite span and I'm guessing the selector will be something like this with a span after it.
>> Mike North: So we've got our debugger fired and let me just make sure that this is doing what I think it's doing.

[00:00:52] Perfect, and so actually before this, I'm gonna set up the sort of listener, the handler for the action in advance of the click. And the action that we fire is on-fav-clicked.
>> Mike North: Make sure it's fired.
>> Mike North: And we need to do one extra thing here actually.
>> Mike North: One.

[00:01:35]
>> Mike North: So the test is finishing before we actually get to what we need to get to. This-
>> Speaker 2: You need to pass that definition of we're actually retriggering, when you instantiate, when you render the object into the. Did you render the component?
>> Mike North: Good point, good point.
>> Mike North: I didn't have my action binding there.

[00:02:07] Did not exist on object.
>> Mike North: You know what I think I can do here, pardon me stumbling through this a little bit.
>> Speaker 2: Shouldn't you mean this.set favoriteWasClicked as a function-
>> Mike North: No, this.set, so I'm doing this here, set my action and then the action handler.
>> Speaker 2: I don't think that's the name of the function, I think you named in something different.

[00:02:59]
>> Mike North: It's the external name of the action and we don't have a run loop on.
>> Mike North: So let me write another piece of the test first.
>> Mike North: Okay, so, looks like the act of clicking on that is not doing what I expect it to do.
>> Mike North: favoriteWasClicked.
>> Mike North: It's very odd.

[00:04:44] Yes, so beyond even the idea of attaching to the action, I would expect it to fire the internal component action and change from favorite to unfavorite.
>> Speaker 3: [INAUDIBLE] this.set [INAUDIBLE] this.set action test [INAUDIBLE] to a function.
>> Mike North: Okay.
>> Speaker 3: And it works.
>> Mike North: So let's give that a shot then.

[00:05:15] So this.set on-fav-clicked, and then I used the binding.
>> Speaker 3: And I passed in favorite clicked equals on-fav-clicked, as a remote.
>> Mike North: So that happened to do it. Interesting, okay, whew. So what I would do here, is just have something like this.
>> Mike North: This will help you catch, two or three times, the action being fired.

[00:06:10]
>> Speaker 4: Except actually how easy it is-
>> Mike North: Yeah, you're right, sorry. And this is still not working as I'd expect, interesting.
>> Speaker 5: So are we just testing if that function fires? Is that what we've got right here?
>> Mike North: So that 'll test that the action is fired. What it does not do and I believe it's because, what it doesn't do is validate that favorite actually changes to unfavorite.

[00:06:44]
>> Speaker 6: In chat they're saying shouldn't you be listening to favorite clicked?
>> Mike North: So I actually think I know what's going on here. We haven't injected the service onto gitHub-org. That is the source of truth for this array. So there is really no way to know whether something's been favorited or not.

[00:07:01] So I'm going to create this here, let's see if that will give us some better luck.
>> Speaker 5: All favorite clicked does is pass through the action, it doesn't test anything with the service. Internal analytic component. When you trigger favorite clicked, it just passes.
>> Speaker 2: Action setting.
>> Speaker 7: It doesn't do anything with the service at all.

[00:07:28] The service is the least favorite property.
>> Mike North: I got you, okay. Sorry, we're getting in the weeds here guys. So I'm gonna just blow this away here and leave this as the test for the component. And move on to the acceptance test in the interest of making sure we get to keep covering stuff here.