I can't successfully unit test my angular.js directive (karma + jasmine)...
Basically, in my directive's compile function, I do replace element contents with a form.
When unit-testing, after
scope = $rootScope;
element = angular.element('<my-directive></my-directive>');
$compile(element)($rootScope);
scope.$digest();
I'd expect to find element to contain my form, with '... abc ...'...
That's not the case... :-(
This is my (simplified) directive:
angular.module('myApp')
.directive('myDirective', function() {
return {
restrict: 'E',
scope: {},
compile: function(element) {
element.replaceWith('<form> ... abc ... </form>');
}
};
});
This is my test:
describe('Directive: paypalButton', function () {
beforeEach(angular.mock.module('myApp'));
var element, scope;
beforeEach(inject(function ($rootScope, $compile) {
scope = $rootScope;
element = angular.element('<my-directive></my-directive>');
$compile(element)($rootScope);
scope.$digest();
}));
it('replaced content should contain abc', function() {
expect(element.html()).toContain('abc');
});
});
The directive works (in the browser I see 'abc'), but the "expect" test always fails: I do not get 'abc' in element's html(), but always get 'xyz'...
I'm sure I'm missing something obvious... :-(