Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. Jasmine testing Angular issues

Jasmine testing Angular issues

Scheduled Pinned Locked Moved JavaScript
csharpjavascriptvisual-studiohelptesting
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cjb110
    wrote on last edited by
    #1

    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 undefined

    I 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.

    C 1 Reply Last reply
    0
    • C cjb110

      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 undefined

      I 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.

      C Offline
      C Offline
      cjb110
      wrote on last edited by
      #2

      Found that by commenting out chunks of my Angular app definition, the test then works. Not sure why, what I assume is an issue with the Angular code, is effecting the operation of the test?

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups