Unit Testing Directive Scope Binding

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 11 years ago
Updated 6 years ago

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

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...

Edgar Martinez
Edgar Martinez
~ 11 years ago

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

Markdown supported.
Become a member to join the discussionEnroll Today