Jasmine testing Angular issues
-
I'm attempting to create jasmine unit tests to an existing Angular web project. But I'm having real problems getting it to work. I'm not very familiar with JavaScript or Angular (far more comfortable in C#), so it could well be a noob mistake. This is all in Visual Studio 2015 with Jasmine 2.4.1 and Angluar 1.5.8. I'm using the Chutzpah addin to run the tests. Jasmine works with noddy tests like 2+2 = 4 :D, but as soon as I try to test the actual app I run into problems. I started with something simple, testing one of the filters. But I've found 4 different approaches but they all fail with what looks to be internal issues (i.e. not the actual test). One test is:
describe('Matterhorn 4', function()
{
describe('SortCodeFilter', function()
{
var createFilter;beforeEach(angular.mock.module('ngRoute', \[\])); beforeEach(angular.mock.module('LocalStorageModule', \[\])); beforeEach(angular.mock.module('angular-loading-bar', \[\])); beforeEach(angular.mock.module('angularUtils.directives.dirPagination', \[\])); beforeEach(function() { module('MatterhornAuthApp', \['ngRoute', 'LocalStorageModule', 'angular-loading-bar', 'angularUtils.directives.dirPagination'\]); inject(function($injector) { createFilter = $injector.get('SortCodeFilter'); }); }); it('should return stuff', function() { expect(createFilter('12345')).toBe('01-23-45'); }); });
});
I think I understand what this is doing, but it fails with things like
Error: [$injector:modulerr] Failed to instantiate module undefined due to:
[ng:areq] Argument 'fn' is not a function, got undefinedI think its references or dependencies, but I've ran out of files to reference at the top of the test:) and can't work out how you work out what the dependencies even are! I suppose I'm used to more help or info being provided by the ide/compiler that helps lead me where to look.
-
I'm attempting to create jasmine unit tests to an existing Angular web project. But I'm having real problems getting it to work. I'm not very familiar with JavaScript or Angular (far more comfortable in C#), so it could well be a noob mistake. This is all in Visual Studio 2015 with Jasmine 2.4.1 and Angluar 1.5.8. I'm using the Chutzpah addin to run the tests. Jasmine works with noddy tests like 2+2 = 4 :D, but as soon as I try to test the actual app I run into problems. I started with something simple, testing one of the filters. But I've found 4 different approaches but they all fail with what looks to be internal issues (i.e. not the actual test). One test is:
describe('Matterhorn 4', function()
{
describe('SortCodeFilter', function()
{
var createFilter;beforeEach(angular.mock.module('ngRoute', \[\])); beforeEach(angular.mock.module('LocalStorageModule', \[\])); beforeEach(angular.mock.module('angular-loading-bar', \[\])); beforeEach(angular.mock.module('angularUtils.directives.dirPagination', \[\])); beforeEach(function() { module('MatterhornAuthApp', \['ngRoute', 'LocalStorageModule', 'angular-loading-bar', 'angularUtils.directives.dirPagination'\]); inject(function($injector) { createFilter = $injector.get('SortCodeFilter'); }); }); it('should return stuff', function() { expect(createFilter('12345')).toBe('01-23-45'); }); });
});
I think I understand what this is doing, but it fails with things like
Error: [$injector:modulerr] Failed to instantiate module undefined due to:
[ng:areq] Argument 'fn' is not a function, got undefinedI think its references or dependencies, but I've ran out of files to reference at the top of the test:) and can't work out how you work out what the dependencies even are! I suppose I'm used to more help or info being provided by the ide/compiler that helps lead me where to look.