2

I am running my tests with karma and phantom, Also I'm using mocha and sinon and tests are getting failed with below error:

EditResourceCategoryDialogTest EditResourceCategoryDialogController "before each" hook: workFn
Error: [$injector:modulerr] http://errors.angularjs.org/1.4.9/$injector/modulerr?p0=resourceofferingsApp&p1=Error%3A%20%5B%24injector%3Amodulerr%5D%20

Sample code:

define(function (require) {
    "use strict";

    var assert = require('chai').assert;
    var sinon = require('sinon');
    var angular = require('angular');
    var angularMocks = require('angular.mocks');

    require('resourceofferings/app');
    require('dialog path');

    describe('EditResourceCategoryDialogTest', function () {

        beforeEach(module('resourceofferingsApp'));

        describe('EditResourceCategoryDialogController', function () {
            var $scope, ctrl;

            //you need to inject dependencies first
            beforeEach(inject(function ($rootScope, $injector) {
                $scope = $rootScope.$new();
            }));

            it('initialization test (create mode)', inject(function ($controller) {

                ctrl = $controller("EditResourceCategoryDialogController", {
                    $scope: $scope,
                    $uibModalInstance: null,
                    options: {
                        isEditMode: false
                    }
                });

                assert.equal($scope.isEditMode, false);
            }));

        });
    });
});

Its exactly getting failed here:

beforeEach(inject(function ($rootScope, $injector) {
    $scope = $rootScope.$new();
}));

Please help me to fix this issue..

Thanks in advance.

Ranjit Kumar
  • 273
  • 2
  • 14

1 Answers1

0

Try this ...

describe('controllers', function(){
    beforeEach(inject(function($rootScope, $controller) {
        scope = $rootScope.$new(); // this is what you missed out
        controller = $controller('EditResourceCategoryDialogController', {
            $scope: scope,
            $uibModalInstance: null,
            options: {
                isEditMode: false
            }
        });
    }));
});

Update: According to Angular ...

A common reason why the module fails to load is that you've forgotten to include the file with the defined module or that the file couldn't be loaded.

Are you sure all needed files are loaded?

dcodesmith
  • 9,285
  • 4
  • 37
  • 38