In the project of Vojta about testing directives What does this code do ?
// load the tabs code
beforeEach(module('tabs'));
It says it loads the tabs code but, why ? Isn't the tabs module already defined next here ?
var tabs = angular.module('tabs', []);
Can some one give a brife explanation of what should be loaded why and how in angular test ?
I tried to call this function in my tests, like this
beforeEach(module('utils')) ;
and I get this error :
TypeError: Property 'module' of object [object Object] is not a function
Also when I try load my templates like this
beforeEach(module('templates/loadingBar.html'));
I get this error :
Error: No module: templates/loadingBar.html
I am really confused about the whole process.
Thanks for helping ...
The code you listed
var tabs = angular.module('tabs', []);
creates the tabs
module, but in order to load it you probably put something like ng-app="tabs"
on an element in your DOM. This instructs Angular to load the tabs
module and make its definitions available to the injector that the app uses to resolve dependencies. (See the Bootstrap guide for more information.)
In your tests, there is no ng-app
directive to initialize the injector or load your module; the module
function (which exists on angular.mock
from the angular-mocks.js
file) does this for you in tests. If you use the Karma Jasmine or Mocha adapter for testing, it makes module
available to you, otherwise you may need to call angular.mock.module
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With