This lesson is for PRO members.

Unlock this lesson NOW!
Already subscribed? sign in

Unit Testing Directive Scope Binding

2:00 Angular 1.x lesson by

Digging a little deeper into unit testing an AngularJS directive, this lesson looks at testing binding across multiple scopes.

Get the Code Now
click to level up

egghead.io comment guidelines

Avatar
egghead.io

Digging a little deeper into unit testing an AngularJS directive, this lesson looks at testing binding across multiple scopes.

Avatar
Theron

Hi

Do you have the full source to this exercise including the karma.conf.js file?

I cannot get this two-way binding example to work for m. I continually get an exception as it seems that I'm getting 2 instances of a $scope. I seem to recall that there was some change to the two way binding isolate scope in a later release of Angular. I'm not sure if I'm running into that.

thanks!!!

In reply to egghead.io
Avatar
Joel

Hi

Do you have the full source to this exercise including the karma.conf.js file?

I cannot get this two-way binding example to work for m. I continually get an exception as it seems that I'm getting 2 instances of a $scope. I seem to recall that there was some change to the two way binding isolate scope in a later release of Angular. I'm not sure if I'm running into that.

thanks!!!

The problem was with element.scope(). You now need to use element.isolateScope(). I've updated the source for the lesson so you can see the correct code for these tests.

In reply to Theron
Avatar
Theron

thank you so much Joel. This works great. Much appreciated!!!

Theron

In reply to Joel
Avatar
Edgar

Using element.isolateScope() def fixed it it was passing no matter what before

John Lindquist: If we want to bind some data between our parent scope and the directive scope. Let's set up some data on the scope. We'll have this have a property of message, which will just be "Hello." Then, we'll test to see if we can get these to both equal hello world. We'll say, should, update both scopes on click. We'll expect the scope and we'll just bind directly to S Simple message to be "Hello world."

This will make more sense in just a second. The say scope data message to be "Hello world." Scope data message right now is just hello. Scope data message is hello and then we'll want to bind this add simple. We'll set up a two way binding, which is going to take the data in and set it here so that once we click.

We say as simple message plus equals space world, then we should get those to pass because now the elements scope, the isolated scope where S simple is bound directly to data. Then we update this that should send the binding back to the root scope which means that this guy will also update.

Both of these will update and equal hello world. So that's how you can test that your communication is working between your directive and parent scopes...

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?