Question

After adding angularStrap module everything works fine except for in my unittest I get the following error:

    Error: No module: $strap.directives
...
    TypeError: Unable to get property 'expect' of undefined or null reference

so var httpBackend = null

I Added it to main module:

var app = angular.module('testK', ["ngResource", "$strap.directives", "ui.if", 'ui.date']);

Added js files to index.html

<!-- AngularJS files -->
        <script type="text/javascript" src="lib/jquery.js"></script>
        <script type="text/javascript" src="lib/jquery-ui-1.10.3.custom.js"></script>
        <!-- <script type="text/javascript" src="lib/jquery-ui-1.10.3.custom_witheffects.js"></script> -->
        <script type="text/javascript" src="lib/angular/angular.js"></script>
        <script type="text/javascript" src="lib/angular/angular-resource.js"></script>
        <!--<script type="text/javascript" src="lib/angular/directives/ng-table.js"></script>-->
        <script type="text/javascript" src="lib/angular/ui/if.js"></script>
        <script type="text/javascript" src="lib/angular/ui/datepicker.js"></script>
        <script type="text/javascript" src="lib/angular/twitter-bootstrap.min.js"></script>
        <script type="text/javascript" src="lib/angular/angular-strap-0.7.5.min.js"></script>

my unittest:

"use strict";
describe("mainT", function () {


 var ctrl, scope, httpBackend, locationMock, 

    beforeEach(module("testK"));
    beforeEach(inject(function ($controller, $rootScope, $httpBackend, $location, $injector) {
        scope = $rootScope.$new();
        httpBackend = $httpBackend;
        locationMock = $location;



        ctrl = $controller("mainT.controller.users", { $scope: scope, $location: locationMock});


    }));

    afterEach(function () {
        httpBackend.verifyNoOutstandingRequest();
        httpBackend.verifyNoOutstandingExpectation();
    });




        describe("method test", function () {
        it('should test', function () {
            //todo implementation
            expect(true).toBeFalsy();
        });
    });
});

When I remove "$strap.directives" from my app module, my unittest works. Anybody got a clue why this strap module isn't found in my unittest?

Was it helpful?

Solution

the karma.conf.js file defines the files that are available during unit tests. It can be used to add mocks or 3rd party modules.

check the karma.conf.js and add the file there:

// base path, that will be used to resolve files and exclude
basePath = '';

// list of files / patterns to load in the browser
files = [
  JASMINE,
  JASMINE_ADAPTER,
  REQUIRE,
  REQUIRE_ADAPTER,
  'test-main.js',
  ...
  ];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top