I am new to AngularJs and have a problem trying to check the directive with a dependency (although the directive itself works as expected). I could not find the answers to these questions or to other resources.
Here is my code:
Directive
angular.module('MyApp') .directive('appVersion', ['config', function (config) { return function (scope, elm) { elm.text(config.version); }; }]);
Service (value):
angular.module('MyApp') .value('config', { version: '0.1' });
Test:
describe('Directive: AppVersion', function () { beforeEach(module('MyApp')); var element; it('should have element text set to config value', inject(function ($rootScope, $compile, config) { var scope = $rootScope; element = $compile('<app-version></app-version>')(scope); expect(element.text()).toBe(config.version); })); });
My test does not work with the message:
Error: Expected '' to be '0.1'.
means the configuration value was entered correctly, but $ complile did not use it. I would really appreciate any help with this. Thanks.
Tiger source share