1

I have a directive that $emit's an event, but in the parent scope of a unit test doesn't get the event.

test $broadcasts an event to the directive, directive gets the event, and then directives $emits its own event, that the parent should get.

unit test:

beforeEach(inject(function ($compile, $rootScope) {
    scope = $rootScope.$new();
    compile = $compile;
}));

element = compile(angular.element('<div myDirective></div>'))(scope);
scope.$digest();

var _scope = element.isolateScope();
scope.$broadcast('directive-change');
scope.$on('directive-successfully-changed', function (e) {});

directive:

 scope.$on('directive-change', function (e) {
    scope.$emit('directive-successfully-changed');
 });
martynas
  • 12,120
  • 3
  • 55
  • 60
puppeteer701
  • 1,225
  • 3
  • 17
  • 33
  • The way I read your code, you're setting the `scope.$on('directive-successfully-changed')` into the directive isolated scope, not a parent. And, what is the purpose of the `_scope` variable (with underscore) ? – glepretre May 05 '14 at 15:39
  • _scope is the scope of a directives controller. I have used rootScope for broadcasting and $on events, and it did not fix the problem – puppeteer701 May 06 '14 at 10:11
  • Could you try to invert your `$broadcast` and `$emit` please? – glepretre May 06 '14 at 13:58

0 Answers0