2

I am trying to test the following directive.

angular.module('myModule.directives', [])
  .directive('test', function() {
    return {
      restrictions: 'E',
      scope: {},
      transclude: true,
      replace: true,
      template: '<div><ui><li>a</li></ul></div>'
    }
});

In my test:

describe('directives', function () {
    var compile,
    scope,
    test;

    beforeEach(module('myModule.directives'));
    beforeEach(inject(function ($compile, $rootScope) {

    compile = $compile;
    scope = $rootScope;
    test = angular.element('<test></test>');
    compile(test)(scope);
    scope.$digest();

    it('should render the test directive', function () {
        var lis = test.find('li');
        console.log(lis.length); // should output 1
    });

}));  

Test fails and outputs 0. I am curious as to whether compile is actually doing anything. If I replace test with

  test = angular.element("<test><li></li></test>");. 

Then the 'find' does find the li within the test element, which goes to show that compile is not rendering to

  '<div><ui><li>a</li></ul></div>' 

as it should. Any ideas? I looked at the following vid for guidance (http://www.youtube.com/watch?v=rB5b67Cg6bc).

1 Answer 1

1

You need to change "restrictions" to "restrict"

Sign up to request clarification or add additional context in comments.

3 Comments

I never realized that mistake. That didn't fix it. I also tried outputting to a variable like you initially commented.
@aaron Did you take a look at the plunkr I made?
Thanks for setting up that example. When I figure out why it doesn't work in my environment, I'll post here. Thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.