Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

issue with unit-testing directive using karma #76

Closed
ajs2 opened this issue Oct 25, 2013 · 2 comments
Closed

issue with unit-testing directive using karma #76

ajs2 opened this issue Oct 25, 2013 · 2 comments

Comments

@ajs2
Copy link

ajs2 commented Oct 25, 2013

I'm unit testing my directive and in my unit test I only have

var scope = $rootScope.$new(),
    element = angular.element('<my-foo></my-foo>');

element = $compile(element)(scope);
scope.$digest();

expect(element.scope()).toBeDefined();

This test fails :( To reproduce this I have created a small angular project here on github, with only 1 directive and only one unit test. To reproduce do

$> git clone https://github.com/ajs2/angularjs-directive
$> npm install
$> bower install
$> karma start karma.conf.js

I was able to fix this test by doing one the following

  1. In the directive add to the 'link' function
$element.data('$scope', $scope);
  1. or change 'replace' into
replace: false 
  1. remove jquery from karma.conf.js

It doesn't make any sense, but it demonstrates that this situation is weird (I think). Can someone comment on this, because after many hours of tweaking I start to think that I have hit a bug here!

@ajs2
Copy link
Author

ajs2 commented Oct 25, 2013

I got the impression this is not the right place for this, copied the question to angular/angular.js#4640

@petebacondarwin
Copy link
Member

You're right!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants